我有两个分隔符‘|’
竖线和‘,’
逗号
'1,100,12345|2,345,433|3,23423,123|4,33,55'
并且必须插入表格列中,如下所示
+-----+---------+--------+
| seq | invoice | amount |
+-----+---------+--------+
| 1 | 100 | 12345 |
| 2 | 345 | 433 |
| 3 | 23423 | 123 |
| 4 | 33 | 55 |
+-----+---------+--------+
请帮忙 谢谢 Prathibha
答案 0 :(得分:1)
单程
DECLARE @S VARCHAR(MAX) = '1,100,12345|2,345,433|3,23423,123|4,33,55'
DECLARE @x xml = '<r><c>' +
REPLACE(REPLACE(@S, ',','</c><c>'),'|','</c></r><r><c>') +
'</c></r>'
SELECT x.value('c[1]','int') AS seq,
x.value('c[2]','int') AS invoice,
x.value('c[3]','int') AS amount
FROM @x.nodes('/r') x(x)