'Query JSON Data using SQL Server OpenJson - ERROR
Not sure what's wrong with this below SQL query. I am getting below error message
'Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.'
Can anyone please help me to fix this query
DECLARE @json NVARCHAR(4000) = N'{
"pets" : {
"cats" : [
{ "id" : 1, "name" : "Fluffy", "gender" : "Female" },
{ "id" : 2, "name" : "Long Tail", "gender" : "Female" },
{ "id" : 3, "name" : "Scratch", "gender" : "Male" }
],
"dogs" : [
{ "name" : "Fetch", "gender" : "Male" },
{ "name" : "Fluffy", "gender" : "Male" },
{ "name" : "Wag", "gender" : "Female" }
]
}
}'
SELECT * FROM OPENJSON(@json, '$.pets.cats')
WITH(
[Cat Id] int,
[Cat Name] varchar(60),
[Gender] varchar(6),
[Cats] nvarchar(max)
);
P.S. I am using SQL server 2017 14.0
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
