I am using SQL Server 2005 for my application. I have a table in my stored procedure which has two columns, C1 and C2. I want to transpose this table such that the values of column C1 becomes the columns. Before transpose (Table 1):
C1 C2
M1 U1
M1 U2
M1 U3
M2 U4
M2 U5
After Transpose (Table 2):
M1 M2
U1 U4
U2 U5
U3 NULL
In Table1, the number of distinct values (M1, M2) may vary. So, the columns in Table2 are not fix.
Please provide a solution to achieve the same.