且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将JSON转换为SQL Server 2016中的表

更新时间:2023-02-03 12:58:42

我找到了一个实际上可以解决该问题的Microsoft页面.

I found a Microsoft page that actually solves the problem.

这是查询的外观:

SELECT *
  FROM OPENJSON(@_l_Table_Data)
  WITH (    Formal_Round_Method        NVARCHAR(16)    '$.Formal_Round_Method'               ,
            Public_Round_Method        NVARCHAR(16)    '$.Public_Round_Method'               ,
            Formal_Precision           INT             '$.Formal_Precision'                  ,
            Public_Precision           INT             '$.Public_Precision'                  ,
            Formal_Significant_Digits  INT             '$.Formal_Significant_Digits'         ,
            Public_Significant_Digits  INT             '$.Public_Significant_Digits'         ,
            General_Comment            NVARCHAR(MAX)   '$.General_Comment'   AS JSON                
    ) ;

因此,您需要在列定义的末尾添加AS JSON,并且(上帝知道为什么)类型必须必须为NVARCHAR(MAX).

So, you need to add AS JSON at the end of the column definition and (God knows why) the type MUST be NVARCHAR(MAX).

确实非常简单!