Splitting CSV Column data to separate records without using any User-Defined Functions

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 665

DECLARE @csv varchar(10)= '1,2,3'
SELECT @CSV CSVData
SELECT p.q.value('.', 'varchar(100)') as word
FROM (SELECT CAST('<Values><Value>' + REPLACE( @csv, ',', '</Value><Value>')
+ '</Value></Values>' AS xml) AS m)t
CROSS APPLY m.nodes('/Values/Value')p(q)


OUTPUT1:
CSVData
1,2,3

OUTPUT2:
Word
1
2
3

Comments or Responses

Posted by: vishalneeraj-24503 on: 7/24/2014 Level:Platinum | Status: [Member] [MVP] | Points: 10
Hi Bandi,

Where we can use your code?
Posted by: vishalneeraj-24503 on: 7/24/2014 Level:Platinum | Status: [Member] [MVP] | Points: 10
I mean in which scenario,we can use your code?

Login to post response