Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change SQL Server for JSON Auto column name?

enter image description here In this picture, result column name(JSON_F52...) is auto-generated by SQL Server. How to change this name to unique name?

like image 840
Ahmad Aghazadeh Avatar asked Jan 23 '18 04:01

Ahmad Aghazadeh


People also ask

How do I automatically format JSON in SQL Server?

Format JSON Output Automatically with AUTO Mode (SQL Server) To format the output of the FOR JSON clause automatically based on the structure of the SELECT statement, specify the AUTO option.

How do I force a JSON query in SQL?

In SQL Server you can use the FOR JSON clause in a query to format the results as JSON. When doing this, you must choose either the AUTO or the PATH option. This article contains examples of using the AUTO option.. Syntax. The syntax goes like this: SELECT ... (your query goes here) FOR JSON AUTO;

How do I change the format of the for JSON clause?

To format the output of the FOR JSON clause automatically based on the structure of the SELECT statement, specify the AUTO option. When you specify the AUTO option, the format of the JSON output is automatically determined based on the order of columns in the SELECT list and their source tables. You can't change this format.

Can I modify the key part of a JSON document in SQL?

If you’ve been using the JSON_MODIFY () function to modify JSON documents in SQL Server, you might be used to modifying the value part of a key/value property. But did you know that you can also modify the key part?


1 Answers

Can use this code:

SELECT (SELECT TOP 100 * FROM [Order] FOR JSON AUTO) AS ColumnName

enter image description here

like image 143
Ahmad Aghazadeh Avatar answered Oct 16 '22 16:10

Ahmad Aghazadeh