Chris Ward
Chris Ward

Reputation: 817

T-SQL FOR JSON PATH but without a column name in the JSON result

Is there a way in SQL to return an array of values without the column name included? I've searched for a solution but have not found anything

CREATE TABLE #data (
    id int
);

INSERT INTO #data VALUES (1)
INSERT INTO #data VALUES (2)
INSERT INTO #data VALUES (3)
INSERT INTO #data VALUES (4)
INSERT INTO #data VALUES (5)
INSERT INTO #data VALUES (6)
INSERT INTO #data VALUES (7)
INSERT INTO #data VALUES (8)
INSERT INTO #data VALUES (9)
INSERT INTO #data VALUES (10)

SELECT id FROM #data FOR JSON PATH

DROP TABLE #data

The above T-SQL returns the below JSON but I want it without the column name just an array of values

[
    {
        "id": 1
    },
    {
        "id": 2
    },
    {
        "id": 3
    },
    {
        "id": 4
    },
    {
        "id": 5
    },
    {
        "id": 6
    },
    {
        "id": 7
    },
    {
        "id": 8
    },
    {
        "id": 9
    },
    {
        "id": 10
    }
]

I would like the resulting output to be:

[
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10
]

Upvotes: 2

Views: 1022

Answers (0)

Related Questions