Reputation: 31
I have an array
(1,2,3,4;5,6,7,8;9,10,11,12;13,14,15,16;)
I want to insert this array of values into the table like
Column1 | Column2 | Column3 | Column4
-----------------------------------------
1 | 2 | 3 | 4
5 | 6 | 7 | 8
9 | 10 | 11 | 12
13 | 14 | 15 | 16
Upvotes: 3
Views: 50898
Reputation: 135
DECLARE @array varchar(max) = '(1,2,3,4;5,6,7,8;9,10,11,12;13,14,15,16;)'
SET @array = REPLACE( REPLACE(@array, ';', '), ('), ', ()', '')
DECLARE @SQLQuery VARCHAR(MAX) = 'INSERT INTO TABLENAME (Column1,Column2,Column3,Column4) VALUES ' + @array
EXEC (@SQLQuery)
Upvotes: 2
Reputation: 930
Try this:
INSERT INTO TableName (Column1,Column2,Column3,Column4)
VALUES (1,2,3,4),(5,6,7,8),(9,10,11,12),(13,14,15,16)
Upvotes: 6
Reputation: 738
INSERT INTO TableName
VALUES
(1,2,3,4),(5,6,7,8),(9,10,11,12),(13,14,15,16)
Upvotes: 1