我从我的repo [1,2,3,4,5]传递了这个数据,它是INSERT INTO CommitteeMember
SELECT
@committeeID,
* // how to call it?
FROM
OPENJSON(@membersJson) AS json
转换为json字符串。
现在我想将它插入数据库。我该如何写我的查询?
document.getElementById
答案 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 强>