SQL Cross Apply String_Split with XML Path

SQL select statement to convert list of IDs found in column (from more than row or listed inside cell with comma separation) inside column, then find the name for each of these IDs from another table and list them in another column for each ID.
So, say we have 3 tables in SQL ...

Posts < Table1.jpg
PostID | PostName

Category (Cats in code example) < Table2.jpg
CatID | CatName

Settings (Alwa7Settings in code example) < Table3.jpg
ObjectID | SettingName | SettingValue
1stPostID | Post-x-CatIDs | ID1, ID2, ID3
2ndPost | Post-x-CatIDs | ID5
2ndPost | Post-x-CatIDs | ID6

What we want is to have in 1 table < Output.jpg
PostID | CategoryIDs | CategoryNames
1stPostID | ID1, ID2, ID3 | Cat1Name, Cat2Name, Cat3Name
2ndPost | ID5, ID6 | Cat5NAme, Cat6Name

As a bonus, select below also lists username for every post from a 4th table based on ID found in Posts table.


SQL below will do that, check screenshots

CodeFunctionName What is this?

Public

Tested

Original Work

Access is limited.

Login here using your Linkedin account. to see or download code.

No registration, not another password to remember, login using your Linkedin account and have access to all public codes in Boldcodes.com

Linkedin Login

Views 286

Downloads 119

CodeID
DB ID