I have a question about SQL Server: how to get json format using a few columns and get columns also?
Table : emp
id | name | sal | depno
----+------+-----+------
1 | a | 100 | 10
2 | b | 200 | 20
Based on this data, I want output like this :
id | name | sal | deptno | empjsonstring
----+------+------+--------+-------------------------------------------
1 | a | 100 | 10 | {"id":1,"name":"a","sal":100,"deptno":10}
2 | b | 200 | 20 | {"id":2,"name":"b","sal"200,"deptno":20}
I tried with this query:
select *
from emp
for json path, include_null_values, without_array_wrapper
but that did not return the expect result.
Could you please tell me how to write a query to achieve this task in SQL Server?
FOR JSON. You'll need to upgrade your instance to a version of SQL Server that does (SQL Server 2016+).