The SQL within a comma-separated field content into a plurality of records

1 select SourceUid from WmsUnPack where State = 9

Results of query

 

 Change the SQL statement

1 select  b.COl2 from  
2      (select SourceUid,COl2=convert(xml,' <root> <v>'+replace(SourceUid,',',' </v> <v>')+' </v> </root>') from WmsUnPack where State = 9)w 
3  outer apply 
4      (select Col2=C.v.value('.','nvarchar(100)') from w.COl2.nodes('/root/v')C(v)) b

search result

 

Guess you like

Origin www.cnblogs.com/Loners/p/11460812.html