将一列转换为 json

Kam*_*ran 2 sql-server azure-sql-server

使用 Azure SQLServer 我试图只将一列转换为 json 格式。数据位于 nvarchar 字段中。使用For Json Auto将转换所有字段和所有行。我需要的只是转换一列。

通过转换为 json,我的意思是可以在 SSMS 中的一个新窗口中点击查看它的数据。

假设表 (Logs) 有 2 列:LogIdLogDataLogDatanvarchar(max)并包含 json 数据。

我需要的是查询表并有一个可点击的logData列。

PSK*_*PSK 5

你可以尝试像下面这样只得到一列 JSON

select o.*,
 (select YourColumnForJson  
    from YourTable i 
        where o.Identifer=i.Identifer for json auto) as JsonColumn 
 from YourTable o
Run Code Online (Sandbox Code Playgroud)