This is a small sample of the data. In the actual data, the values under Name and Code are in the hundreds and those values change frequently. For this reason, hard-coding the Pivot statement will not work. There needs to be a dynamic SQL statement created - and I need help with that.
DECLARE @Test Table
(
Name Varchar(32),
Code Varchar(20)
)
INSERT INTO @Test(Name, Code) VALUES
('A-1', 'A-One')
, ('A 2', 'A-Two')
, ('B 1-b', 'B-One')
, ('B', 'A-Two')
, ('C', 'A-One')
, ('C', 'B-One')
, ('C', 'C-One')
The sample data set looks like this [again, this is just a small sample]:
Name Code
A-1 A-One
A 1 A-Two
B 1-b B-One
B A-Two
C A-One
C B-One
C C-One
Notice that Code values [like A-One, A-Two, and B-One] may be associated with more than one Name value.
E.g. A-One appears with Name A-1, as well as Name C ...
I want to output it so it looks like this [except, with a lot more values than I am showing - and those values can change]:
A-1 A 1 B 1-b B C
A-One X X
A-Two X X
B-One X X
C-One X
The number of 'Name' values and Code values can change. They are not constant.
The goal is to be able to look down the list of Code values on the left - and easily see which Name values the Codes are associated with.
I believe this requires dynamic pivot sql to be created and I have trouble understanding Pivot sql and I would appreciate any help or pointers.

(1)Create a query that returns a list of all the distinct names in your table.(2)declare a variable type NVARCHAR(MAX).(3)CONCAT all these values from step 1 into your variable from step 2.(4)create simple pivot query using specific list of names - not yet a dynamic query... if you did all these steps well then you only need to combine all together, and i came to the limitation of the message length :-) show steps 1-4Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime". Unfortunately most people race for points and not to teach, and posting the final query is much faster and simpler than going step by step and following the thread for long time. My interest is only in helping those who want to learn how to do it themselves, and not to work for free and provide final query if you cannot learn from it :-)