SQL SERVER 分割符转列
--分割符转列
select ParsedData.* from new_systemparameterbase mt cross apply ( select str = mt.New_value + ',,' ) f1 cross apply ( select p1 = charindex( ',', str ) ) ap1 cross apply ( select p2 = charindex( ',', str, p1 + 1 ) ) ap2 cross apply ( select p3 = charindex( ',', str, p2 + 1 ) ) ap3 cross apply ( select p4 = charindex( ',', str, p3 + 1 ) ) ap4 cross apply ( select p5 = charindex( ',', str, p4 + 1 ) ) ap5 cross apply ( select p6 = charindex( ',', str, p5 + 1 ) ) ap6 cross apply ( select substring( str, 1, p1-1 ) a1 , substring( str, p1+1, p2-p1-1 ) a2 , substring( str, p2+1, p3-p2-1 ) a3 , substring( str, p3+1, p4-p3-1 ) a4 , substring( str, p4+1, p5-p4-1 ) a5 , substring( str, p5+1, p6-p5-1 ) a6 ) ParsedData where mt.new_name ='detectionorderproductwarehouseaddress'