Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 converting Degress/Minutes/Seconds- Decim LAT/LONG

Author  Topic 

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2012-11-27 : 17:36:56
Hi Friends,

I have a table called customers with Lat Long fields.
Can some please provide me with a function to converting LAT/LONG which is in Degrees/Minutes/Seconds to Decimal .




BobsDesk
Starting Member

11 Posts

Posted - 2012-11-27 : 18:05:36
Can you describe the data you have in more detail? Assuming its some type of text string your challenge will be formatting and consistency. If the degrees, minutes and seconds are fields you could simply follow this example:
http://kb.tableausoftware.com/articles/knowledgebase/convert-latitude-longitude

Robert '); drop table students;-- ?
Go to Top of Page

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2012-11-28 : 10:55:47
Hi Bobs Desk..tanks for the response.

My Lat field data is like this :30° 16' 16.9998"
Longitude field :-93° 17' 58.5198"
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-11-28 : 11:42:17
Can you post the results of these queries? Replace the reds with the appropriate column and table names. Also, for at least one row of the result of the second query, post the covnerted result that you want to see.

SELECT COLUMN_NAME,
DATA_TYPE
FROM INFORMATION_SCHEMA.[COLUMNS] c
WHERE c.TABLE_NAME = 'YourTableNameHere'
AND c.COLUMN_NAME = 'YourColumnNameHere';

SELECT TOP (5)
YourColumnNameHere
FROM
YourTableNameHere
Go to Top of Page

BobsDesk
Starting Member

11 Posts

Posted - 2012-11-28 : 12:38:16
sunitabeck may have a better idea once we know the type of your data. The below would work assuming the data is consistent and contains the ° ' " symbols in that order but will not warn you if it does not. If your data type is some kind of (n)varchar you might look to converting it to normalized data, Google Maps has allot of free tools
Select
(Abs(SubString(Lat, 0, CharIndex('°', Lat)))
+ (SubString(Lat, CharIndex('°', Lat) + 1, CharIndex(Char(39), Lat) - CharIndex('°', Lat) - 1) / 60.0)
+ (SubString(Lat, CharIndex(Char(39), Lat) + 1, CharIndex('"', Lat) - CharIndex(Char(39), Lat) - 1) / 3600.0))
* Sign(SubString(Lat, 0, CharIndex('°', Lat)))
, (Abs(SubString(Lng, 0, CharIndex('°', Lng)))
+ (SubString(Lng, CharIndex('°', Lng) + 1, CharIndex(Char(39), Lng) - CharIndex('°', Lng) - 1) / 60.0)
+ (SubString(Lng, CharIndex(Char(39), Lng) + 1, CharIndex('"', Lng) - CharIndex(Char(39), Lng) - 1) / 3600.0))
* Sign(SubString(Lng, 0, CharIndex('°', Lng)))
From @Table


PS, is that your house? Big front yard...

Robert '); drop table students;-- ?
Go to Top of Page
   

- Advertisement -