SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 mySQL syntax
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sg2255551
Constraint Violating Yak Guru

272 Posts

Posted - 12/04/2012 :  20:30:34  Show Profile  Reply with Quote
hi

I have this sql syntax in MySQL. What is equivalent for MSSQL 2008? Thanks

$lat = -31,52;
$lon = -68,52;

$multiplier = 112.12; // use 69.0467669 if you want miles
$distance = 10; // kilometers or miles if 69.0467669

$query = "SELECT *, (SQRT(POW((lat - $lat), 2) + POW((lng - $lng), 2)) * $multiplier) AS distance FROM routes WHERE POW((lat - $lat), 2) + POW((lng - $lng), 2) < POW(($distance / $multiplier), 2) ORDER BY distance ASC";

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 12/04/2012 :  21:13:49  Show Profile  Reply with Quote

Declare @lat float,@lon float,@multiplier float,@distance float

Set @lat =  -3152
Set @lon = -6852
Set @multiplier = 112.12
Set @distance = 10


SELECT *, 
(SQRT(POWER((lat - @lat), 2)) + POWER((lng - @lon), 2)) * @multiplier) AS distance 
 FROM routes 
 WHERE POWER((lat - @lat), 2)) + POWER((lng - @lon), 2)) < POW((@distance / @multiplier), 2) 
 ORDER BY distance ASC

Edited by - sodeep on 12/04/2012 21:15:39
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000