交叉加入SqlServer

时间:2018-04-03 07:30:56

标签: sql asp.net sql-server

查询我试过

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-debit-amount

enter image description here

1 个答案:

答案 0 :(得分: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));
                 }


            }