| Author |
Topic |
|
sign_seventh
Yak Posting Veteran
66 Posts |
Posted - 2008-04-09 : 23:38:22
|
this is my sample records in my tableSdate AmountJanuary 2007 250000.00March 2007 300000.00January 2008 350000.00 how can i get the amount from January to May 2007 and sum it up like thisDetailsJanuary 2007 250000.00February 2007 250000.00March 2007 300000.00April 2007 300000.00May 2007 300000.00 this is all that i want to getTotal Amount: 1,400,000.00 |
|
|
pravin14u
Posting Yak Master
246 Posts |
Posted - 2008-04-09 : 23:51:23
|
| Select Sdate,Amount from TableName UNIONSelect 'Total Amount',sum(Amount) from TableNamePrakash.PThe secret to creativity is knowing how to hide your sources! |
 |
|
|
sign_seventh
Yak Posting Veteran
66 Posts |
Posted - 2008-04-10 : 00:56:09
|
this will only gave me the total of all amount.quote: Originally posted by pravin14u Select Sdate,Amount from TableName UNIONSelect 'Total Amount',sum(Amount) from TableNamePrakash.PThe secret to creativity is knowing how to hide your sources!
|
 |
|
|
pravin14u
Posting Yak Master
246 Posts |
Posted - 2008-04-10 : 01:02:03
|
quote: Originally posted by sign_seventh this will only gave me the total of all amount.quote: Originally posted by pravin14u Select Sdate,Amount from TableName UNIONSelect 'Total Amount',sum(Amount) from TableNamePrakash.PThe secret to creativity is knowing how to hide your sources!
Select Sdate,Amount from TableName UNIONSelect 'Total Amount,sum(Amount) from TableNamewhere SDate in('January 2007','February 2007','March 2007','April2007','May 2007')Prakash.PThe secret to creativity is knowing how to hide your sources! |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2008-04-10 : 01:04:05
|
where did these rows come from in your first result set:February 2007 250000.00April 2007 300000.00May 2007 300000.00are they supposed to be inferred based on the most recent month that actually has data in your sdate/amt table? elsasoft.org |
 |
|
|
sign_seventh
Yak Posting Veteran
66 Posts |
Posted - 2008-04-10 : 02:05:00
|
| the original content of that table is actually this but to make it short i only choose the quo_user_id = 23quo_id | quo_datetime| quo_amount| quo_user_id7 | 2007-07-01 |500000.00 |2041 | 2008-01-01 |550000.00 |2044 | 2008-01-01 |350000.00 |2311 | 2007-01-01 |250000.00 |2312 | 2007-03-01 |300000.00 |2342 | 2008-01-01 |300000.00 |2714 | 2007-01-01 |250000.00 |2815 | 2007-03-01 |300000.00 |28 |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2008-04-10 : 02:30:57
|
so what's wrong with pravin14u's answer then? elsasoft.org |
 |
|
|
sign_seventh
Yak Posting Veteran
66 Posts |
Posted - 2008-04-10 : 03:13:23
|
| theres nothing wrong in his code, i actually tried it.i just want a dynamic one. like what if i want to get amount fr febuary '07 to march '08. i dnt want to put from feb 07 up to march 08 in my 'in clause'. |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2008-04-10 : 03:22:20
|
Select Sdate,Amount from TableNamewhere SDate between @startDate and @endDateUNION ALLSelect 'Total Amount,sum(Amount) from TableNamewhere SDate between @startDate and @endDate elsasoft.org |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-10 : 05:30:47
|
What is wrong with GROUP BY and ROLLUP? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|