selectsum(income) Income,sum(Expenses) Expenses,paymode from #Test groupby paymode
Output :
Income Expenses paymode
1200 501 cash
100 501 Cheque
+1
Nitin SontakkeRank #264 · 9.6K reputationPosted Feb 28, 2017, 7:06 PM EST
+1
I had posted a reply to your earlier question http://www.c-sharpcorner.com/forums/need-cash-amount-separate-and-cheque-separate to which never respond, which is not good!
Anyway....
selectsum(casewhen PayMode = 'Cash'then Income else 0.00 end) [CashIncome]
select 1 as ID,@from as Date, cast(0 as varchar) as BillNo,''as Customer,'Opening' as Types,isnull(sum(Income),0)-isnull(sum(Expenses),0) as Income,0.00 as Expenses,'Cash' as PayMode from fn_getLedger()
where convert(varchar,date,112)
union all
select ID,Date,BillNo,Customer,Types,Income,Expenses,Paymode from fn_getLedger()
where convert(varchar,date,112)>=convert(varchar,@from,112) and convert(varchar,date,112)<=convert(varchar,@to,112)
order by date
end
this is the procedure
+1
Rafnas T PRank #280 · 8.8K reputationPosted Feb 28, 2017, 7:27 PM EST
+1
you have datatable right for binding data to this grid
then try this
C#
DataTable dt = GetSampleDataTable(); //Get the table above.
dt = dt.Select("SELECT sum(Income) as Income, sum(Expenses) as Expences,
PayMode GROUP BY PayMode order by PayMode );
txttotincomecash.Text=dt.Rows[0][0].ToString();
txttotincomecheck.Text=dt.Rows[1][0].ToString();
txttotExpencecash.Text=dt.Rows[0][1].ToString();
txttotExpencecheck.Text=dt.Rows[1][1].ToString();
C#
+1
Rafnas T PRank #280 · 8.8K reputationPosted Feb 28, 2017, 7:30 PM EST
dt = dt.Select("SELECT sum(Income) as Income, sum(Expenses) as Expences, PayMode GROUP BY PayMode order by PayMode ); txttotincomecash.Text=dt.Rows[0][0].ToString(); txttotincomecheck.Text=dt.Rows[1][0].ToString(); txttotExpencecash.Text=dt.Rows[0][1].ToString(); txttotExpencecheck.Text=dt.Rows[1][1].ToString();
Joginder BangerRank #360 · 7K reputationPosted Feb 28, 2017, 7:04 PM EST
Nitin SontakkeRank #264 · 9.6K reputationPosted Feb 28, 2017, 7:06 PM EST
yesubabu kRank #2,091 · 687 reputationPosted Feb 28, 2017, 7:11 PM EST
Nitin SontakkeRank #264 · 9.6K reputationPosted Feb 28, 2017, 7:13 PM EST
Rafnas T PRank #280 · 8.8K reputationPosted Feb 28, 2017, 7:14 PM EST
yesubabu kRank #2,091 · 687 reputationPosted Feb 28, 2017, 7:15 PM EST
yesubabu kRank #2,091 · 687 reputationPosted Feb 28, 2017, 7:17 PM EST
yesubabu kRank #2,091 · 687 reputationPosted Feb 28, 2017, 7:20 PM EST
Rafnas T PRank #280 · 8.8K reputationPosted Feb 28, 2017, 7:27 PM EST
Rafnas T PRank #280 · 8.8K reputationPosted Feb 28, 2017, 7:30 PM EST
PayMode GROUP BY PayMode order by PayMode );
txttotincomecash.Text=dt.Rows[0][0].ToString();
txttotincomecheck.Text=dt.Rows[1][0].ToString();
txttotExpencecash.Text=dt.Rows[0][1].ToString();
txttotExpencecheck.Text=dt.Rows[1][1].ToString();
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts