经纬度度分秒转换小数.sql[原创]

--Make data for test

declare @T table(lat varchar(50),lon varchar(50))

insert into @T select '14°′″','14°′″' union all

select '12°′″','15°′″' union all

select '33°′″','34°′″' union all

select '16°′″','94°′″' union all

select '46°′″','74°′″' union all

select '56°′″','16°′″'

 

--Test mark

select lat,Charindex('°',lat) '°',

         Charindex('′',lat) '′',

         Charindex('″',lat) '″',

       lon,Charindex('°',lon) '°',

         Charindex('′',lon) '′',

         Charindex('″',lon) '″'

from @T

 

--make temp data

if object_id('tempdb..#t') is not null

begin

    drop table #t

end

 

select lat,Substring(lat,1,Charindex('°',lat)-1) 'latdegree',

           Substring(lat,Charindex('°',lat)+1,Charindex('′',lat)-1-Charindex('°',lat)) 'latcent',

           Substring(lat,Charindex('′',lat)+1,Charindex('″',lat)-1-Charindex('′',lat)) 'latsecond',

       lon,Substring(lon,1,Charindex('°',lon)-1) 'londegree',

           Substring(lon,Charindex('°',lon)+1,Charindex('′',lon)-1-Charindex('°',lon)) 'loncent',

           Substring(lon,Charindex('′',lon)+1,Charindex('″',lon)-1-Charindex('′',lon)) 'lonsecond'

into #t

from @T

 

--Make result

declare @multiplycent int

declare @multiplysecond int

declare @dividecent int

declare @dividesecond int

declare @divide float

set @multiplycent =1000000

set @multiplysecond = 100000

set @dividecent=6

set @dividesecond=36

set @divide = 10000000.0

 

if object_id('tempdb..#result') is not null

begin

    drop table #result

end

select lat,latdegree,latcent,latsecond,

       latdegree+str(latcent*@multiplycent/@dividecent+latsecond*@multiplysecond/@dividesecond)/@divide as 'decimallat',

       lon,londegree,loncent,lonsecond,

       londegree+str(loncent*@multiplycent/@dividecent+lonsecond*@multiplysecond/@dividesecond)/@divide as 'decimallon'

into #result

from #t

 

--View the result data round decimal six bit

select lat,decimallat,lon,decimallon,Round(decimallat,6) as resuldlat,Round(decimallon,6) as resultlon from #result

 

13972900_200809111312421.jpg

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/13972900/viewspace-444250/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/13972900/viewspace-444250/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值