All,
Not quite sure how to do the following. Teaching myself SQL, working with SQL Server 2008 R2. Note that while I can perform all the select queries I like, I do not have the permissions to create drop tables in the database.
In my database, there's a table called "messages." Each message is a three letter code (e.g., 'AAA', 'AAB', etc.). Each primary key can have an arbitrary number of messages. So, for purposes of this exercise, say the table looks like this:
1 AAA
1 AAB
1 AAC
2 AAA
2 CCC
etc,
The output I would like to get is to convert this horizontal data to vertical data so I can get this:
1 AAA AAB AAC
2 AAA CCC
If relevant, the database also contains a list of all the possible message codes on a different table.
I suspect the correct answer involves PIVOT, but I am not quite sure how to get there. The closest I found is this: How to pivot table with T-SQL? However, (a) I wasn't sure how to adapt it to my situation and (b) it appears to require creating a table.
Thank you in advance.