In one of my previous posts I wrote about “How to Create a Comma Delimited List”. Now I’ll show you an example with reverse action, that is Splitting a Comma Delimited String or array() of values.
There can be different types of Delimiters also : like Comma ' , ', vertical bar ' | ', Single space or a Tab.
For example here is our Sample Table -
And here is the expected output -
Create Sample Data :
-- Create Table for Sample Data
-- Verify the Sample Data
And here is the query for How to split a comma delimited string :
;WITH Cte AS
Acknowledgement : Well seriously don’t know. Somewhere I came across this solution while answering / participating on MSDN Sql Server Forums. So credit goes to my fellow Moderators/answrers on MSDN Forums.
Actually whatever expertise I gained on T-SQL and Sql Server is by participating / answering to the posts on online forums. I’m one of those freaks who hate to read books ;)
- Mangal Pardeshi