交叉加入SqlServer

问题描述 投票:0回答:1

查询我试过了

select '' as Date,'opening Balance' as Descriptions ,0.00 as credit,0.00 as 
 debit,Opening as Balance from dbo.Setting
 where Opening!=0

 union all 

 select  (convert(Varchar(20),EDate,105)) as Date,LocName as 
Descriptions,Amount as credit,0.00 as debit,Opening+Amount  as Balance
from dbo.CashInward
inner join dbo.OutletMst ON dbo.OutletMst.LocId = CashInward.OutletId
cross join setting 
where Edate=convert(Datetime,'03/Apr/2018',105) and deletes!=1 and 
Outletmst.Active=1 and Amount!=0

union all

select  (convert(Varchar(20),EDate,105)) as Date,AcName as 
Descriptions,Amount as credit,0.00 as debit,Opening+Amount  as Balance  
from dbo.IncExpEntry
inner join dbo.AccountMst ON dbo.AccountMst.Acid = IncExpEntry.Acid
cross join setting
where ETYpe =1 and Edate=convert(Datetime,'03/Apr/2018',105) and Amount!=0

union all

select (convert(Varchar(20),EDate,105)) as Date,AcName as Descriptions,0.00 
as credit,Amount as debit,Opening-Amount  as Balance from dbo.IncExpEntry
inner join dbo.AccountMst ON dbo.AccountMst.Acid = IncExpEntry.Acid
cross join setting
where ETYpe =2 and Edate=convert(Datetime,'03/Apr/2018',105)  and Amount!=0

o / p

enter image description here

我希望余额作为信贷然后6700000 +信贷其他借记6700000借记但第2,第3,...行我想要6700000 +信贷+金额其他670000-借方金额

enter image description here

sql asp.net sql-server
1个回答
1
投票

回答

      foreach (GridViewRow row in Daybook.Rows)
            {
                string type1 = "0.00";
                string type2 = "0.00";
                 string opening=ltype.Text;
                 string opening2;

               //  int index = row.RowIndex - 1;
                 if (row.Cells[1].Text != type1)
                {

                        decimal Amount = Convert.ToDecimal(row.Cells[1].Text);
                        Decimal Total = Convert.ToDecimal(opening) + Amount;
                        row.Cells[3].Text = Convert.ToString(Math.Round(Total, 2));
                        //opening2 = Total.ToString();


                }
                 if (row.Cells[2].Text != type2)
                 {
                     decimal Amount = Convert.ToDecimal(row.Cells[2].Text);
                     Decimal Total = Convert.ToDecimal(opening) - Amount;
                     row.Cells[3].Text = Convert.ToString(Math.Round(Total, 2));
                 }


            }
© www.soinside.com 2019 - 2024. All rights reserved.