I have a database of all US Zip codes. I've put together syntax to pull all zip codes from a radius of miles. I have two additional tasks to perform:
1. Calculate distance from each record returned to the original zip code
2. Use the result set from the query below to pull customer data from a view (v_customer_info_by_zipcode)
TIA
Jason
declare @distance int, @targetZip int
select @distance = 50
select @targetZip = 21223
SELECT DISTINCT t1.City, t1.State, t1.ZipCode, t1.Latitude, t1.Longitude
FROM ZipCodeDatabase t1
JOIN ZipCodeDatabase t2 ON (3963.0*acos(sin(t1.Latitude/(180/PI())) * sin(t2.Latitude/(180/PI())) + cos(t1.Latitude/(180/PI())) * cos(t2.Latitude/(180/PI())) * cos(t2.Longitude/(180/PI())-t1.Longitude/(180/PI())))<@distance)
WHERE t2.ZipCode=@targetZip
ORDER BY t1.ZipCode
1. Calculate distance from each record returned to the original zip code
2. Use the result set from the query below to pull customer data from a view (v_customer_info_by_zipcode)
TIA
Jason
declare @distance int, @targetZip int
select @distance = 50
select @targetZip = 21223
SELECT DISTINCT t1.City, t1.State, t1.ZipCode, t1.Latitude, t1.Longitude
FROM ZipCodeDatabase t1
JOIN ZipCodeDatabase t2 ON (3963.0*acos(sin(t1.Latitude/(180/PI())) * sin(t2.Latitude/(180/PI())) + cos(t1.Latitude/(180/PI())) * cos(t2.Latitude/(180/PI())) * cos(t2.Longitude/(180/PI())-t1.Longitude/(180/PI())))<@distance)
WHERE t2.ZipCode=@targetZip
ORDER BY t1.ZipCode