Click here to Skip to main content
15,886,106 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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'.

SQL
 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.
Posted
Updated 4-Feb-13 1:03am
v2
Comments
Sandeep Mewara 19-Jan-13 15:40pm    
First thing, never use keywords like 'Date' in your query.

Nope.

You can't convert rows into columns and vice versa with a simple query,
however, you can easily do this in your code, iterate through rows (or cols) and on each step pick up the Nth index of the other for each col (row).

Cheers,
Edo
 
Share this answer
 
this way..

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

Happy Coding!
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900