Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
table_1

Name_____Date_________Ptype
Keadr____22/2/2010____P
Anup_____22/2/2010____P
Deepak___22/2/2010____A
Keadr____23/2/2010____P
Anup_____23/2/2010____L
Deepak___23/2/2010____A
Keadr____24/2/2010____P
Anup_____24/2/2010____P
Deepak___24/2/2010____P



I want To convert this table as

Name_____22/2/2010____23/2/2010_____24/2/2010
Kedar____P____________P_____________P
Anup_____P____________L_____________P
Deepak___A____________A_____________P





my query

select * from table_1 PIVOT(MAX(Ptype)FOR[Date]IN([22/2/2010],[23/2/2010],[24/2/2010]))AS p




i got result

Name_____22/2/2010______23/2/2010______24/2/2010
Kedar
Anup
Deepak


didnt get values in 22/2 ,23/2,24/3 col

plz help me
Posted
Updated 23-Feb-10 17:51pm
v4

1 solution

select * from table_1 
PIVOT(MAX(Ptype) FOR [Dates] IN ([22/2/2010],[23/2/2010],[24/2/2010]))AS p


Is fine, but the column name [Dates] doesn't match the [Date] in your table above. Testing the table and the SQL works fine IF your column names match and the [Dates] column is text (I didn't try make it work with a "date" data type).
 
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