declare @Path as nvarchar(100)
set @path = '$.path.to."sub-object"'
DECLARE @json NVARCHAR(4000) = N'{
"path": {
"to":{
"sub-object":["en-GB", "en-UK","de-AT","es-AR","sr-Cyrl"]
}
}
}';
SELECT [key], value
FROM OPENJSON(@json, @Path)
I got error:
Incorrect syntax near '@Path'.
how to declare @path that i can change it.
Passing path as variable to OPENJSON is available from SQL Server 2017
(aka vNext):
In SQL Server 2017 and in Azure SQL Database, you can provide a variable as the value of path.
declare @Path as nvarchar(100)
set @path = '$.path.to."sub-object"'
DECLARE @json NVARCHAR(4000) = N'{
"path": {
"to":{
"sub-object":["en-GB", "en-UK","de-AT","es-AR","sr-Cyrl"]
}
}
}';
SELECT [key], value
FROM OPENJSON(@json, @Path);
DbFiddle Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With