Invalid syntax in working construction. SQL Server 16
I keep getting 'incorrect syntax near "$[0]".'
Here is the code.
INSERT INTO CompuconTaxi.dbo.Regions (name, region_name, polygon)
SELECT
'tes' AS name,
'asd' AS region_name,
geography::STPolyFromText('POLYGON ((' + STRING_AGG(CAST(Long + ' ' + Lat as varchar(max)), ',') + '))',4326).ReorientObject() AS polygon
FROM
(
SELECT
Long,
Lat
FROM
OPENJSON(N'{
"type": "Feature", "properties": {"region_name": "test2", "name": "test" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 23.8580303, 38.1225949 ], [ 23.8578422, 38.1225496 ]]] }
}', '$.geometry.coordinates[0]')
WITH
(
Long varchar(100) '$[0]',
Lat varchar(100) '$[1]'
)
)d
Here is tutorial link i user, to produce this code
The trouble is that this code works as intended, which is bullshit. Any ideas?
SELECT
Long,
Lat
FROM
OPENJSON(N'{
"type": "Feature", "properties": {"region_name": "test2", "name": "test" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 23.8580303, 38.1225949 ], [ 23.8578422, 38.1225496 ]]] }
}', '$.geometry.coordinates[0]')
WITH
(
Long varchar(100) '$[0]',
Lat varchar(100) '$[1]'
)