Is it different to update geography column in sql server than a regular field( varchar....). Can you please provide a sample statement to do this. thanks.
If we want to add multiple columns to the existing table using any single statement, we can use the below syntax: ALTER TABLE table_name (Name of the table) ADD [COLUMN] column_definition, (for adding column)
Returns a geometry instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation augmented with any Z (elevation) and M (measure) values carried by the instance.
I am not sure if this is the answer you are looking for - but as I would say, the main difference is that when updating a "regular field", you typically provide directly the 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 it is a very long hexadecimal number, which encodes the geoghraphy information) but you will want to compute it from some other values (which can, but do not have to be columns of the same table), e.g.:
UPDATE mytable SET gps=geography::STPointFromText('POINT(' + lng + ' ' + lat + ')', 4326)
where lng
and lat
are varchar values specifying the GPS coordinates in a "human-readable" format (like lat = '48.955790'
, lng = '20.524500'
) - in this case they are also columns of mytable
.
If you have Latitude and Longitude as decimals, you can update a 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;
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