Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-06-07 : 22:15:29
|
Query1--------SELECT MONTH(date)as date, sum(qty) as qty FROM #TempSt_trx WHERE date>='2007-01-01 00:00:00.000' and date<='2007-12-31 00:00:00.000' GROUP BY dateQuery 1 will generate result intodate qty1 102 203 155 166 70Query 2SELECT SUM(qty)as qty FROM #TempSt_trx where date <'2007-01-01 00:00:00.000'Query 2 will generate result into165How i going to combine both result into date qty1 102 203 155 166 7013 165coz Query 2 is the balance in previous year. Query 1 will group all records into month and i wanna display query2 as month 13 with the sum |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-06-07 : 22:18:22
|
use union allSELECT MONTH(date)as date, sum(qty) as qtyFROM #TempSt_trxWHERE date>='2007-01-01 00:00:00.000' and date<='2007-12-31 00:00:00.000'GROUP BY dateunion allSELECT 13 as date, SUM(qty)as qty FROM #TempSt_trx where date <'2007-01-01 00:00:00.000' KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-06-07 : 22:18:28
|
| select * from(SELECT MONTH(date)as date, sum(qty) as qty FROM #TempSt_trx WHERE date>='2007-01-01 00:00:00.000' and date<='2007-12-31 00:00:00.000' GROUP BY dateunionSELECT 13 as date, SUM(qty)as qty FROM #TempSt_trx where date <'2007-01-01 00:00:00.000')awoops done |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-06-07 : 22:21:02
|
| khtan...could u help me in my sto-pro...>"<http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=127101 |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-06-07 : 22:34:51
|
| hehehe, same here...i jz on top u...mal |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-06-07 : 23:07:31
|
quote: Originally posted by waterduck hehehe, same here...i jz on top u...mal
Go and take your teh tarik first  KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|
|
|