SQL Server 2016,将json和非json一起返回

时间:2018-01-31 14:32:15

标签: sql json sql-server-2016

有没有办法将json和非json数据一起返回?例如:

# A tibble: 6 x 4
# Groups: fact [2]
   fact    id value newvar
  <dbl> <int> <dbl>  <dbl>
1  1.00     1  NA     44.0
2  1.00     2  44.0   23.0
3  1.00     3  23.0   NA  
4  2.00     4  NA     76.0
5  2.00     5  NA     NA  
6  2.00     6  76.0   NA  

1 个答案:

答案 0 :(得分:0)

尝试使用AS JSON

DECLARE @json NVARCHAR(MAX) = N'  
{  
  "Other":[{
    "something": "value", 
    "column2": "value2"}],
    "Id": 1
}'  

SELECT *
FROM OPENJSON ( @json )  
WITH (   
  [Id] int '$.Id',
  [Other]  nvarchar(MAX)  AS JSON  
)