I have got a JOIN between transactions and Cards, simplified it looks like this:
TranID Date Card ShopType ShopName
11 2018-01-25 15:45:29.000 119317903 S ShopA
12 2018-01-25 16:31:01.000 119317903 S ShopB
13 2018-01-25 13:39:08.000 119325674 G ShopC
14 2018-01-25 15:43:35.000 119325674 S ShopA
15 2018-01-25 16:31:15.000 119325674 S ShopD
I want to create a new table with one row per card, including all transactions and details of that card. Number of transactions can vary. So desired result would be:
Card TranID_1 Date_1 ShopType_1 ShopName_1 TranID_2 Date_2 ShopType_2 ShopName_2 TranID_3 Date_3 ShopType_3 ShopName_3
119317903 11 2018-01-25 15:45:29.000 S ShopA 12 2018-01-25 16:31:01.000 S ShopB
119325674 13 2018-01-25 13:39:08.000 G ShopC 14 2018-01-25 15:43:35.000 S ShopA 15 2018-01-25 16:31:15.000 S ShopD
I Found this on SO, but I can't quite get the dynamic SQL syntax to work for me. (dynamic SQL always gets the better of me).
Efficiently convert rows to columns in sql server
Any help would be greatly appreciated.
Thanks in Advance!