Skip to content
Advertisement

SQL switch latitude and longitude positions in the polygon string

I have a text that contains polygon information

Example data:

it there any way that could swap “lat” and “lng” in this string in SQL Server?

Expect outcome:

Any help appreciate!

Advertisement

Answer

What you have here is JSON. You can break out the info using OPENJSON, swap it round, and rebuild it using FOR JSON:

db<>fiddle

If you have a table that you want to select from, you would do it like this

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement