Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

SQL – Select Closest Locations

Posted on September 15, 2017 By David Kittell

This is an older script but still works nicely.

Setup: You have a table with medical centers that has the address along with latitude and longitude columns.

I used this script with a GPS application that pulled your current location and sent it to a web service to get the results.

GPS Provided Latitude: 43.0011
GPS Provided Longitude: -83.7742

SELECT TOP 20 *, ( 3959 * acos( cos( radians(43.0011) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-83.7742) ) + sin( radians(43.0011) ) * sin( radians( lat ) ) ) ) AS distance 
FROM MedicalCenters 
WHERE ( 3959 * acos( cos( radians(43.0011) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-83.7742) ) + sin( radians(43.0011) ) * sin( radians( lat ) ) ) ) < 250
ORDER BY distance
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code MSSQL SQL

Post navigation

Previous post
Next post

Related Posts

PowerShell Set DNS Settings

Posted on September 24, 2015October 16, 2015

This only works on Windows 8, 8.1, 10 as the Cmdlets Set-DnsClientServerAddress Get-DnsClientServerAddress are introduced in Windows 8. First get the interface name(s) you want to modify Get-DnsClientServerAddress Change the code below to the interface you wish to change $primarydns = $args[0] $secondarydns = $args[1] Set-DNSClientServerAddress –interfaceAlias Wi-Fi –ServerAddresses ($primarydns,$secondarydns)…

Read More

Age Verification

Posted on December 16, 2013October 26, 2015

private bool ValidateMemberUnderage(DateTime dtBirthday, int nYears) { if (DateTime.Today.Year – dtBirthday.Year > nYears) return true; else if (DateTime.Today.Year – dtBirthday.Year == nYears) { DateTime dtBirthdayThisYear = dtBirthday.AddYears(nYears); if (DateTime.Today >= dtBirthdayThisYear) return true; else return false; } else return false; } if (ValidateMemberUnderage(DateTime.Parse("1981-04-04"), 12) == false) { MessageBox.Show("Too Young"); }…

Read More

Raspberry Pi – Remove Default Apps

Posted on July 19, 2017March 26, 2019

If you setup your Raspberry Pi using the NOOBs installer you likely have various apps that you don’t want to keep. This script below will remove many of the preinstalled applications. wolfram-engine bluej geany greenfoot nodered nuscratch scratch sonic-pi libreoffice claws-mail claws-mail-i18n minecraft-pi pygame for i in wolfram-engine \ bluej…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes