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)
 Convert Rows into columns

Author  Topic 

naveendkt
Starting Member

5 Posts

Posted - 2011-08-30 : 13:42:29
I got a table values as bellow.

CREATE TABLE #temp3 (ID INT,Date DATETIME,totalcount INT)

id date totalcount
5 2011-07-30 2
5 2011-07-16 1
5 2011-07-23 2
77 2011-07-16 1
77 2011-08-28 1
77 2011-07-10 1
152 2011-07-03 1

And I want the output as

id 2011-07-30 2011-07-16 2011-07-23 2011-08-28 2011-07-10 2011-07-03
5 2 0 0 0 0 0
77 0 1 0 1 1 0
152 0 0 0 0 0 1

FYI: The rows in #temp3 is dynamic. The dates are not static.

I am using Microsoft SQL Server 2000 - (Build 3790: Service Pack 2)

Can any one help please

Naveen

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-31 : 00:06:39
see


http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/dynamic-crosstab-with-multiple-pivot-columns.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -