Home Forums SQL Server 7,2000 T-SQL Transpose rows to columns - not a crosstab RE: Transpose rows to columns - not a crosstab

  • Using case statements won't work unless I can dynamically generate the number of case statements since the table width may vary.

    Ken- basically what i want to do is transpose row values to column values like a crosstab, but using the values not an aggregate value.  So, for example, currently the values are stored as id/value pairs associated with an id (ID,controlID,value).  So each row in the table would be something like the following: 

    1,1,0

    1,2,'test'

    2,1,4

    2,2,'foo'

    This data id represents the control values for both controls 1 and 2 for ID's 1 and 2.  In tabular view it would be:

            Control(1)     Control(2)

    ID(1)      1              'test'

    ID(2)      4               'foo'

     

    I need to convert the original table to a tabular representation like above.  So the final table would be:

    1,1,'test

    2,4,'foo'

     

    Hope this helps clarify things.

     

    Thanks in advance.