Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2008
    Posts
    120

    Unanswered: MS SQL equivalent of MYSQL Statement

    Hi all....
    I'm following some sample code that produces a 'find nearest store' app.
    It's written in php and the database used is MySQL.

    Could someone help with the statement below to make it MS SQL friendly?

    Code:
    SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20;
    Thank in advance
    Andy

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Code:
    SELECT TOP 20 id, distance
       FROM (SELECT ( 3959 * acos( cos( radians(37) ) 
    *     cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) 
    +     sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance
          FROM markers) AS a
       WHERE distance < 25 
       ORDER BY distance;
    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Jan 2013
    Posts
    354
    Provided Answers: 1
    As an aside, does anyone know the math for HTM neighbors? HTM Overview

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •