I am working with spatial data type in a table. I have the Latitude and Longitude fields. One field serves for the spatial data type field Geography and is defined GeographyTemporary Varchar(100).
So, basically, with the Latitude and Longitude fields, I have the values. Then, from there, I can populate the GeographyTemporary field with this:
DECLARE @Latitude Float
DECLARE @Longitude Float
DECLARE @Numero Int
SET @Latitude=43.704414
SET @Longitude=-79.431849
SET @Numero=452
UPDATE Client
SET Latitude=@Latitude,Longitude=@Longitude,
GeographyTemporary='POINT('+CONVERT(VARCHAR(100),Longitude)+' '+CONVERT(VARCHAR(100),Latitude)+')'
WHERE Client.Numero=@Numero
So, this places a value like this in the GeographyTemporary field:
POINT(-79.43185 43.70441)
The GeographyTemporary field is defined Varchar(100). If I change it to Char(100), it gives an error in the UPDATE line after I adjust the syntax for the type CHAR(100) in both locations where the CONVERT() occurs in the SET line. Why is it that Varchar(100) would work and not Char(100)?
Also, why is it needed to define Varchar(100) on that field if the maximum lenght of the POINT definition would be 27 characters? Could Varchar(27) be sufficient?
For informational purposes, GeographyTemporary is used so I can use it later on to dump into the spatial data type such as this:
DECLARE @Numero Int
SET @Numero=452
UPDATE CLIENT
SET Geography=geography::STGeomFromText(GeographyTemporary,4326)
WHERE Client.Numero=@Numero