SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

akpaga
Constraint Violating Yak Guru

USA
311 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 .




BobsDesk
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:
http://kb.tableausoftware.com/articles/knowledgebase/convert-latitude-longitude

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

akpaga
Constraint Violating Yak Guru

USA
311 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

sunitabeck
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.

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

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

BobsDesk
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
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;-- ?

Edited by - BobsDesk on 11/28/2012 12:39:15
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.08 seconds. Powered By: Snitz Forums 2000