Skip to content
Advertisement

Correct json formatting in ms sql server

I have the following SQL table

I wrote this code to format result as JSON, but can’t get it in the desired format. If i name all product columns as name then sql returns an error Use different names and aliases for each column in SELECT list.

Sql code:

Current output:

Desired output:

Advertisement

Answer

You may try with the next approach:

Table:

Statement:

Result:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement