SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot jsk137's Avatar
    Join Date
    Jan 2002
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    convert this SQL statement to MySQL

    Hello,

    Can someone help me out by converting this SQL statement to by used in MySQL.

    Code:
      CREATE PROCEDURE zip_nearby_locations 
    @lat1 float, 
    @long1 float,
    @radius float
    AS 
    SELECT (2*3956*ASIN( 
    (SQRT( POWER(SIN(((rlat-@lat1))/2),2) + COS(@lat1) * COS(rlat) 
    				  * POWER(SIN(((abs(rlong)-@long1))/2),2) )) ) 
    ) AS dist, location, zipcode
    FROM Zipcodes 
    WHERE (2*3956*ASIN( 
    (SQRT( POWER(SIN(((rlat-@lat1))/2),2) + COS(@lat1) * COS(rlat) 
    				  * POWER(SIN(((abs(rlong)-@long1))/2),2) )) ) 
    ) < @radius
    ORDER BY dist
    GO
     
    I know that MySQL doesn't support stored procedures, but I need to get this into a useable form for Php/MySQL.

    Thanks for your help.

    Jeff

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    based on a quick check in the mysql docs, all the functions ASIN, SQRT, POWER, SIN, COS are available in MySQL with those exact same function names

    try running the query as is, see what you get
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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