【问题标题】:Extract the Data from Json to Table where Id is in Key将数据从 Json 提取到 Id 位于 Key 中的表中
【发布时间】:2020-08-09 09:50:55
【问题描述】:

我正在尝试使用 SQL 函数 JSON_QUERY(表达式 [,路径])将下面的 Json 转换为表。当我使用它时,我无法定义路径,因为 ID 在密钥中并且 ID 会超时。有什么方法可以将这种 json 格式转换/加载到表格中?

【问题讨论】:

  • 请告诉我们您是如何尝试解决问题的(简单的工作代码示例)

标签: python json sql-server json-query


【解决方案1】:

您可以使用 OPENJSON 表值函数来实现它:

SELECT  ch.[key] as checklistId, 
        JSON_VALUE (ch.[value] ,'$.isChecked') as isChecked,
        JSON_VALUE (ch.[value],'$.orderHint') as orderHint

FROM OPENJSON (@json,'$.checklist') ch;

【讨论】:

    猜你喜欢
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-19
    • 2021-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多