I would like to output the results of a SELECT statement as a JSON object.
id name active Status
1 Bob Jones 1 Active
2 John Smith 0 Inactive
I need return result like this:
{"Active" :[{"id":1,"name":"Bob Jones" ,"active":1}],
"InActive":[{"id":2,"name":"John Smith","active":0}]}
How to use the query?
I am using this code
DECLARE @JSONTierDetails AS TABLE (TierDetails VARCHAR(8000))
INSERT INTO @JSONTierDetails
SELECT
(SELECT id, name, active
FROM MyTable
WHERE Status = 'Active'
FOR JSON PATH, INCLUDE_NULL_VALUES) TierDetails
SELECT TierDetails
FROM @JSONTierDetails
Thanks in advance