sql server clr json to table


背景

  SQL SERVER 2016 之前版本不支持 直接解析json

步骤:

1 vs 数据库项目

2 生成dll

3 加入信任

DECLARE @hash AS BINARY(64) = (SELECT HASHBYTES('SHA2_512', (SELECT * FROM OPENROWSET (BULK 'C:\Users\BianGX\source\repos\JsonSQLCLR\JsonSQLCLR\bin\Debug\JsonSQLCLR.dll', SINGLE_BLOB) AS [Data])))

EXEC sp_add_trusted_assembly @hash,N'JsonSQLCLR '

4 添加程序集

5 创建存储过程

  CREATE PROCEDURE[dbo].[Json2Table] (
    @jsonString NVARCHAR(max)
   
    )
    WITH EXECUTE AS CALLER        
    AS
    EXTERNAL NAME JsonSQLCLR.StoredProcedures.Json2Table    --[SQL程序集名].[命名空间.类名].[方法名]

SQL