OPENJSON存储过程[1,2,3,4,5]

时间:2017-09-06 15:19:23

标签: sql sql-server tsql stored-procedures

我从我的repo [1,2,3,4,5]传递了这个数据,它是INSERT INTO CommitteeMember SELECT @committeeID, * // how to call it? FROM OPENJSON(@membersJson) AS json 转换为json字符串。

现在我想将它插入数据库。我该如何写我的查询?

document.getElementById

1 个答案:

答案 0 :(得分:1)

如果我理解你,你想要下面的东西:

CREATE TABLE CommitteeMember(committeeID INT, memberID INT);

DECLARE @membersJSON NVARCHAR(MAX) = '[1,2,3,4,5]';
DECLARE @commiteeID INT = 10;

INSERT INTO CommitteeMember(committeeId, memberId)
SELECT @commiteeID AS committeeId,value AS memberId
FROM OPENJSON(@membersJSON);

SELECT *
FROM CommitteeMember;

<强> Dbfiddle Demo