narasiman rao

narasiman rao

  • NA
  • 519
  • 768.5k

convert rows into columns using query

Jan 19 2013 5:24 AM




 Date             Session  Code             [Table name Schedule]
1/14/2013        1        CM
1/14/2013        3       CM
 
From the above i want the output as follows;
 

                     1           3            [Session]
1/14/2013   CM        CM         [Code]
 

how to get the above output using query in sql server.
 
how can i do.please help me.
 
i tried the below query it is not working showing error as Incorrect syntax near '1'.
 

SELECT
Date,1,3
FROM
Schedule
PIVOT (MAX([Code]) FOR Session IN (1,3)) P
 

how can i get the correct output using query tell me.please reply the answer.

Answers (1)