All I'm trying to do is take a column and create a simple JSON ARRAY from it. FOR JSON is driving me nuts. The below code ...
DECLARE @t TABLE (name VARCHAR (64))
INSERT INTO @t
SELECT value
FROM OPENJSON ('["b","c"]', '$')
SELECT name
FROM @t
FOR JSON AUTO
... yields ...
[{"name":"b"},{"name":"c"}]
... but what I want is ...
[ "b", "c" ]
My problem is I have to say SELECT and the moment I do that the array spewed out has a Name-Value pair in each JSON ARRAY element. I'm thinking this should be simple, or am I just going about it the wrong way and need to use some STRING functions? Ultimately I want to assign the result to a VARCHAR anyways.
If question seems silly, want to clarify I'm getting lots of JSON arrays which I want to convert to single column tables and do SET operations like INTERSECT, UNION and EXCEPT and ultimately land with a final single column table which I then want to return as a simple JSON ARRAY.
SELECT '[ "' + string_agg(name, '", "') + '" ]' FROM @t;?