I have the following SQL Statement:
SELECT
(
SELECT TOP 1
Site.Reference,
(
SELECT TOP 1 ProjectId FROM Project WHERE Project.Siteid = Site.SiteId ORDER BY ProjectId ASC
) AS FirstId,
(
SELECT TOP 1 ProjectId FROM Project WHERE Project.Siteid = Site.SiteId ORDER BY ProjectId DESC
) AS LastId
FROM
Site
WHERE
(Site.SiteId = 348)
FOR JSON PATH, ROOT('seriesdata')
) AS JSONData
Site is the parent and Project is the child in a one-to-many relationship.
The output from this Query is:
JSONData
{"seriesdata":[{"Reference":"SIT0003237","FirstId":216,"LastId":1263}]}
The output I require is :
JSONData
{"seriesdata":[{"Reference":"SIT0003237","IdRange":[216,1263]}]}
I am failing to find how to implement this in SQL Server with the use of the JSON functionality. I would be grateful for any help to find a solution.