SQL Server lat;lng varchar split procedure to use as Lat and Lng for speed Searching

依然范特西╮ 提交于 2019-12-24 02:43:27

问题


Can someone help me using a stored procedure or function to passing my stored varchar lat;lng in table to individuals fields as float as Lat and Lng to use in radius search.

lanlng in Table
33.0000;15.222222

Thanks


回答1:


Are you just trying to split the string? If so:

declare @LatLng varchar(100)
set @LatLng = '33.0000;15.222222'

declare @Lat float
declare @Lng float

select @Lat = CAST(LEFT(@LatLng, charindex(';',@LatLng)-1) as float)
select @Lng = CAST(SUBSTRING(@LatLng, charindex(';',@LatLng)+1, LEN(@LatLng)-charindex(';',@LatLng)) as float)

select @Lat as Latitude, @Lng as Longitude



回答2:


SQL Server Zipcode Latitude/Longitude proximity distance search might be of help to you, look at the functions on that page



来源:https://stackoverflow.com/questions/3873619/sql-server-latlng-varchar-split-procedure-to-use-as-lat-and-lng-for-speed-searc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!