Monday, December 2, 2013

Comma seprated value in multiple rows sql server

Comma seprated value in multiple rows sql server


Above is my output after executing the query but i want to to separated  row means multiple row splitting the taskid column by ' , '.

After so many searches and some modification i able to create a query which is very helpful for me -


SELECT  
     Split.a.value('.', 'VARCHAR(100)') AS taskid,  A.invoiceid,A.Rate
 FROM  (SELECT 
         CAST ('<M>' + REPLACE([taskids], ',', '</M><M>') + '</M>' AS XML) AS String , [invoiceid],[Rate]
     FROM  SMOInvoiceHistory) AS A CROSS APPLY String.nodes ('/M') AS Split(a)


Comma seprated value in multiple rows sql server
Happy Coding...........

No comments:

Post a Comment