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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 converting Degress/Minutes/Seconds- Decim LAT/LONG
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Constraint Violating Yak Guru

331 Posts

Posted - 11/27/2012 :  17:36:56  Show Profile  Reply with Quote
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 .

Starting Member

11 Posts

Posted - 11/27/2012 :  18:05:36  Show Profile  Reply with Quote
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:

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

Constraint Violating Yak Guru

331 Posts

Posted - 11/28/2012 :  10:55:47  Show Profile  Reply with Quote
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

Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/28/2012 :  11:42:17  Show Profile  Reply with Quote
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.

WHERE  c.TABLE_NAME = 'YourTableNameHere'
       AND c.COLUMN_NAME = 'YourColumnNameHere';

Edited by - sunitabeck on 11/28/2012 11:42:39
Go to Top of Page

Starting Member

11 Posts

Posted - 11/28/2012 :  12:38:16  Show Profile  Reply with Quote
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
(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;-- ?

Edited by - BobsDesk on 11/28/2012 12:39:15
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000