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 |
Dragomir
Starting Member
4 Posts |
Posted - 2006-11-21 : 10:26:25
|
Hello everybody,I have a problem.I want to make query that return quatities of diferent car makes month by month in the year.Example:Audi 1 2 3 4 5 6 7 8 9 10 11 12BMW 1 2 3 4 5 6 7 8 9 10 11 12...Can anyone help meThx |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-21 : 10:33:41
|
select cartypecolumn,sum(case when monthvalue = 1 then amountsoldcolumn else 0 end) 'January',sum(case when monthvalue = 2 then amountsoldcolumn else 0 end) 'February',sum(case when monthvalue = 3 then amountsoldcolumn else 0 end) 'March',sum(case when monthvalue = 4 then amountsoldcolumn else 0 end) 'April',sum(case when monthvalue = 5 then amountsoldcolumn else 0 end) 'May',sum(case when monthvalue = 6 then amountsoldcolumn else 0 end) 'June',sum(case when monthvalue = 7 then amountsoldcolumn else 0 end) 'July',sum(case when monthvalue = 8 then amountsoldcolumn else 0 end) 'August',sum(case when monthvalue = 9 then amountsoldcolumn else 0 end) 'September',sum(case when monthvalue = 10 then amountsoldcolumn else 0 end) 'October',sum(case when monthvalue = 11 then amountsoldcolumn else 0 end) 'November',sum(case when monthvalue = 12 then amountsoldcolumn else 0 end) 'December'from yourtablegroup by cartypecolumnorder by cartypecolumnPeter LarssonHelsingborg, Sweden |
 |
|
Dragomir
Starting Member
4 Posts |
Posted - 2006-11-21 : 10:58:14
|
That was exactly what I needed.Thank you very much |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-11-21 : 11:29:13
|
Also read about Cross-tab reports in sql server help file for more informationsMadhivananFailing to plan is Planning to fail |
 |
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2006-11-21 : 14:52:48
|
I'm liking PIVOT on 2K5 for these types of things ...Jay White |
 |
|
graz
Chief SQLTeam Crack Dealer
4149 Posts |
Posted - 2006-11-21 : 16:35:44
|
(Moved to the Transact-SQL forum from the Articles forum)===============================================Creating tomorrow's legacy systems today.One crisis at a time. |
 |
|
|
|
|
|
|