Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Spatial data type and Varchar(100)
Message
 
À
20/11/2011 15:42:24
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01529320
Message ID:
01529321
Vues:
40
This message has been marked as a message which has helped to the initial question of the thread.
>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)?


Because both CONVERT() exceeds the defined length of the field.
UPDATE ... SET ...
           GeographyTemporary='POINT('+CONVERT(CHAR(100),Longitude)+' '+CONVERT(CHAR(100),Latitude)+')'
Will give you total length of 208 and the field is defined as 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?
>
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform