简体   繁体   中英

How to change JSON Column name in sql server 2016

How can I change the column name "JSON_F52......" to Any(eg SalesOrder)

在此输入图像描述

Wrap your json building SELECT in another SELECT:

SELECT (
      SELECT SalesOrderNumber AS 'Order.Number',
             OrderDate AS 'Order.Date'
        FROM Sales.SalesOrderHeader
         FOR JSON PATH
) AS SalesOrder

i think the final result will not have anything with that name, it is a temporary name to store the result..

If you want the result in a variable The output of the FOR JSON clause is of type NVARCHAR(MAX) , so you can assign it to any variable, as shown in the following example.

DECLARE @SalesOrder NVARCHAR(MAX) = (SELECT TOP 10 * FROM Sales.SalesOrderHeader FOR JSON AUTO)

Then select from @SalesOrder

If you want to store it in a file then check this link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM