具有多行具有逗号分隔值的行的表,要在其他表的列中插入每个值

时间:2019-05-31 07:27:25

标签: sql sql-server tsql

我需要插入查询。也许:

insert tblTestTable (TestData) 
select value from STRING_SPLIT((select MyData from tblMyTable), ',')

1 个答案:

答案 0 :(得分:0)

类似这样的东西:

CREATE TABLE TableA
(ColumnToSplit VARCHAR(500))
GO
INSERT INTO TableA
SELECT 'A,B,C'
UNION ALL
SELECT 'A,F,G'
UNION ALL
SELECT 'D,E,H'
GO

SELECT value FROM TableA CROSS APPLY STRING_SPLIT(ColumnToSplit, ',') GO