24 Mar 2012

Using Cross Apply to convert comma separated fields to row


  SELECT A.mapgroupno,
     Split.a.value('.', 'VARCHAR(100)') AS String
 FROM  (SELECT MMapmodulelocation.mapgroupno,
         CAST ('<M>' + REPLACE(MMapmodulelocation.mapdnwlperson, ',', '</M><M>') + '</M>' AS XML) AS String
     FROM  MMapmodulelocation) AS A CROSS APPLY String.nodes ('/M') AS Split(a);

No comments:

Post a Comment