I currently have a table with all the data, using this data i want to create another table which could be used for auditing purpose (similar layout like pivot table)
Example Below:
Raw Data
Name Places Visited
----------------------------
Will London
John Toronto
Dave New York
Will London
What I want (similar to Pivot Table but I can use letters):
Name/Places Visted London Toronto New York
Will Y N Y
John N Y N
Dave N N Y
Any help to produce this will be much appreciated!
I hope i’ve explained myself well but let me know if you would like to clarify anything.
Many Thanks!!
Solution for SQL Server 2005/2008:
Results:
Note: Columns resulting from
PIVOToperation are static. This means that if you add records withPlace='PARIS'you should modify the query like this:PIVOT( MAX(src.Place) FOR src.Place IN([London], [Toronto], [New York], [Paris]). So, you could usePIVOToperator if you have a limited number of cities.