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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Query Question for Row as Column Data no aggregate

Author  Topic 

WoodstockCat
Starting Member

1 Post

Posted - 2005-04-19 : 16:27:32
Hi all. I am working on an ASP.NET application that has data in a table in this format:

CategoryID SubCategoryID Month ItemData
1 1 Jan 500
1 2 Jan 800
1 1 Feb 600
1 2 Feb 900

I want to have the months at the top of the output
CategoryID SubCategoryID Jan Feb
1 1 500 600
1 2 800 900

There are no "sums" or totals involved..I don't need an agreegate value from ItemData but I do need the column values going across by Date..

Any help would be greatly appreciated..

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2005-04-19 : 17:07:25
[code]
select
CategoryID,
SubCategoryID,
case when month = 'jan' then ItemData else null end,
case when month = 'feb' then ItemData else null end,
case when month = 'mar' then ItemData else null end,
... and so on until ...
case when month = 'dec' then ItemData else null end
from
Mytable
order by
CategoryID,
SubCategoryID[/code]

CODO ERGO SUM
Go to Top of Page
   

- Advertisement -