I have a table with rows like below
StoreId | ToyId
-------------------
100 | Toy1
100 | Toy2
101 | Toy1
102 | Toy1
103 | Toy1
103 | Toy2
103 | Toy3
The number of ToyID per store is not limited to 3. A store can have one or many toy ids. I want to get result as:
StoreId | ToyId1 | ToyId2 | ToyId3
-----------------------------------
100 | Toy1 | Toy2 | NULL
101 | Toy1 | NULL | NULL
102 | Toy1 | NULL | NULL
103 | Toy1 | Toy2 | Toy3
How can i achieve in SQL? It is not entire row to column pivoting, The rows dynamically get added based on number of unique rows of one column only.