我正在尝试将 JSON 数组加入到 SQL Server 中的表中(希望避免使用 TVP)。
表数据
| item_id | qty |
|-----------|-----|
| dur 20001 | 1 |
| dur 93677 | 1 |
SQL
declare @json nvarchar(max) = '[{
"order":{
"address":{
"addLine": "123 ABC Ln.",
"citySt": "Los Angeles, CA"'
},
"items":[
"line":{
"id":"ABC 12345",
"qty":"1"
}]}, {
"order":{
"address":{
"addLine": "987 Def Ln.",
"citySt": "Los Angeles, CA"
},
"items":[
"line":{
"id":"DEF 12345",
"qty":"1"
}]}
]'
select *
from someTable st
inner join @json
on vt.item_id in (select json_value(@json,'$.items[0].line.id')
from openjson(@json,'$.items[0]'))
但是,我收到以下错误:
必须声明表变量“@json”。
如何someTable
以这种形式加入 JSON?