Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I am storing lattitude in sql server as below format like 12°20'30". But now i want to split the lattitude in sql server like 12 DEG 20 MIN 30 SEC. Please provide me the solution

What I have tried:

Hello,
              I am storing lattitude in sql server as below format like 12°20'30". But now i want to split the lattitude in sql server like 12 DEG 20 MIN 30 SEC. Please provide me the solution
Posted
Updated 8-Feb-19 4:07am
Comments
RedDk 8-Feb-19 17:40pm    
Ok,

Perhaps I'd be paraphrasing OG in Solution 1 by stating that without knowing which version of SQL Server you're targetting, saying something like "There is a better as well as built-in geospatial data storage facility in SQL Server 2008 which exposes decimal longitude/latitude operations without troubling manual haversine computation. Which you're heading for using the above input NVARCHAR/VARCHAR string representations"

You're not really on the fence though. So, don't NOT do what OG says in his SELECT paste just because he says not to do it.

1 solution

Don't do this in SQL: while it is possible, it's very messy:
SQL
SELECT REPLACE(REPLACE(REPLACE(ColumnNameContainingLattitude, N'°', N' DEG ' ), N'''', ' MIN '), N'"', ' SEC') FROM MyTable

Either do it in your presentation software, or better, store it as three integer values LatDegrees, LatMinutes, and LatSeconds instead of as a single string then use those to generate your string.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900