我想将 JSON 对象传递给 SQL Server 2016 存储过程,而不反序列化对象并让数据库处理数据。
我传入:
DECLARE @json NVarChar(2048) = N'[{
"PMID": "31390573",
"pubdate": "2019",
"data": {
"memberID": "1692",
"pmid": "31390573",
"sortpubdate": "2019/08/06 00:00",
"pmc": "PMC6733019"
}
}, {
"PMID": "31213464",
"pubdate": "2019",
"data": {
"memberID": "1692",
"pmid": "31213464",
"sortpubdate": "2019/08/15 00:00",
"pmc": "PMC6753942"
}
}, {
"PMID": "31130363",
"pubdate": "2019",
"data": {
"memberID": "1692",
"pmid": "31130363",
"sortpubdate": "2019/06/20 00:00",
"pmc": "PMC6588466"
}
}]'
如果我使用
SELECT * FROM OPENJSON(@json);
我明白了
0 { "PMID": "31390573", "pubdate": "2019", "data": { "memberID": "1692", "pmid": "31390573", "sortpubdate": "2019/08/06 00:00", "pmc": "PMC6733019" } } 5
1 { "PMID": "31213464", "pubdate": "2019", "data": { "memberID": "1692", "pmid": "31213464", "sortpubdate": "2019/08/15 00:00", "pmc": "PMC6753942" } } 5
2 { "PMID": "31130363", "pubdate": "2019", "data": { "memberID": "1692", "pmid": "31130363", "sortpubdate": "2019/06/20 00:00", "pmc": "PMC6588466" } } 5
我想最终得到一个表,其中一列用于数据元素中的项目,因此一列用于 memberID -- pmid --sortpubdate--pmc。
memberID pmid sortpubdate
------------------------------------------------
1692 31390573 2019-08-06 00:00:00.0000000
1692 31213464 2019-08-15 00:00:00.0000000
1692 31130363 2019-06-20 00:00:00.0000000
这可能吗?如果它是 XML,它可以被撕开和处理。