SQL Server : query columns to JSON object with group by

后端 未结 4 2039
有刺的猬
有刺的猬 2021-02-14 08:16

I have a table with 3 columns, I want to query that table such that the result will be a JSON object.

Sample data looks like this:

 CREATE TABLE #Test (         


        
4条回答
  •  我在风中等你
    2021-02-14 09:10

    Try this:

    SELECT (SELECT [ID], [Keys], [ValueV]  FOR JSON PATH)
    FROM #Test 
    GROUP BY ID, keys, ValueV
    

    or this:

    SELECT (SELECT [ID], [Keys], [ValueV]  FOR JSON PATH, WITHOUT_ARRAY_WRAPPER)
    FROM #Test 
    GROUP BY ID, keys, ValueV
    

提交回复
热议问题