January 22, 2008 at 11:44 pm
Hi All,
I have a table with following cols. monthwon int,Productcategory varchar(100)
and revenue float.
I want the result in below given format
ProductCategory Jan Feb March
A 2000 5633 589
B 1000 6421 4589
C 3266 1575 4469
Can I do this in a single query.
Thanks
Ahmad
Regards,
[font="Verdana"]Sqlfrenzy[/font]
January 23, 2008 at 12:28 am
- search for 'pivot' in the forums at SSC, you'll find some examples.
- you'll need to build your query with sql2000
something linke
select group1, group2,
, sum(case when detailcolumn = 1 then detailvalue else null end ) as 'detailcolumn_1'
, sum(case when detailcolumn = 2 then detailvalue else null end ) as 'detailcolumn_2'
...
from yourtable(s)
group by group1, group2
order by ...
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
January 23, 2008 at 5:33 am
This is a cross post...
http://www.sqlservercentral.com/Forums/Topic445746-145-1.aspx#bm446281
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply