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
 SQL Server Development (2000)
 Dynamic crosstab

Author  Topic 

chloee
Starting Member

13 Posts

Posted - 2004-07-06 : 08:51:50
Hi guys,

I have a table with the following structure

my_id int
column_name varchar(200)
column_value varchar(200)
column_order int

I need to generate a query that will show results in the following form
my_id, column_name_1, column_name_2...
1 value1 value2
2 value1 value2

The final result should be in txt format.

Problems are
1 - it needs to be dynamic, I don't know column number/name in advance.
2 - I need to order them by column_order

I tried CASE to convert rows to column. I can order the columns to my needs but with too many columns it gives an error.

I tried different dynamic crosstab stored procedures with I have found on the internet, same problem.

The only working solution I have is an access with TRANSFORM and PIVOT and it works like charm, but I can't figure out how to order the columns.

I'm lost! :) Any ideas are highly appreciated.

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-07-06 : 10:12:39
Have you had a look at the following article?

http://www.sqlteam.com/item.asp?ItemID=2955
Go to Top of Page

chloee
Starting Member

13 Posts

Posted - 2004-07-07 : 07:32:36
I tried this crosstab stored procedure and it works!
Thanks!!!
Go to Top of Page
   

- Advertisement -