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)
 SQL 2000 Command Help

Author  Topic 

harmonium
Starting Member

5 Posts

Posted - 2008-11-24 : 13:59:31
I have a table that has data that appears like:

ID Date (YYYYMM)
01 200811
01 200808
01 200712
01 200704
01 200607
01 200603
01 199805
02 200803
02 200704
02 200611
03 200705
03 200309
03 199912
03 199607
03 199408
...

I want to rearrange the data so it appears in a table or result set like this:
ID D1 D2 D3 D4 D5 D6
01 200811 200808 200712 200704 200607 200603
02 200803 200704 200611
03 200705 200309 199912 199607 199408


Can I do this without looping through all the ID's?

Thank you,

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-11-24 : 14:06:58
Will data be consistent? Use cross tabs or Dynamic cross tabs query for it.
Go to Top of Page

harmonium
Starting Member

5 Posts

Posted - 2008-11-24 : 14:23:17
quote:
Originally posted by sodeep

Will data be consistent? Use cross tabs or Dynamic cross tabs query for it.



ID will be consistent, Date format will be consistent, the number of Dates to ID will not be consistent. I am looking into cross tabs and then Dynamic cross tabs now.
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-11-24 : 18:29:01
Read this:

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

- Advertisement -