Update statement - geography column - sql server

The difference in updating the geography column on the sql server than a regular field (varchar ....). Can you provide a sample application for this. Thank you

+6
source share
2 answers

I'm not sure if this is the answer you are looking for - but, as I would say, the main difference is that when updating the "regular field" you usually provide a directly new value, for example:

UPDATE mytable SET name = 'John' WHERE id = 1 

When updating a geography column, you probably cannot provide the value directly (since this is a very long hexadecimal number that encodes geography information), but you want to calculate it from some other values ​​(which may, but should not be, columns of the same table), for example :

 UPDATE mytable SET gps=geography::STPointFromText('POINT(' + lng + ' ' + lat + ')', 4326) 

where lng and lat are varchar values ​​defining GPS coordinates in a "human- lat = '48.955790' " format (for example, lat = '48.955790' , lng = '20.524500' )), in this case they are also mytable columns.

+11
source

If you have Latitude and Longitude as decimals, you can update the geography column as shown below:

 DECLARE @latitude DECIMAL(15,6) ,@longitude DECIMAL(15,6); SET @latitude = 29.938580; SET @longitude = -81.337384; UPDATE Properties SET Geog = GEOGRAPHY::Point(@latitude, @longitude, 4326) WHERE PropertyID = 858; 
0
source

Source: https://habr.com/ru/post/902372/


All Articles