Question : Can not convert a mssql query to a mysql query

Hi I am converting a asp website on a windows server to php on a linux and am having trouble converting one of the mssqls to mysql.

Here is the query as a mssql:

SELECT DISTINCT(v2_dealers.ID), name, town, County, CAST(SQRT(SQUARE(" & x & " - ISNULL(tbl_Postcodes.xCoord, 2000000)) + SQUARE(" & y & " - ISNULL(tbl_Postcodes.yCoord, 200000))) / 1000 * 0.62 AS Int) AS Dist " & _
                  "FROM v2_dealers INNER JOIN v2_dealerbrands ON v2_dealers.ID=v2_dealerbrands.dealer LEFT OUTER JOIN tbl_Postcodes ON v2_dealers.Postcode=tbl_Postcodes.PC "& _
                  "left join tbl_rvlibrary on v2_dealerbrands.make=tbl_rvlibrary.make " & _
                  "WHERE v2_dealers.status='OK' and v2_dealers.id in (select ds.dealer from v2_dealersites ds,v2_sites s where s.id=ds.site and url='"&thissite&"') " & _
                  "and tbl_rvlibrary.rvid='" & rvID & "' " & _
                  "AND (SQRT(SQUARE(" & x & "- ISNULL(tbl_Postcodes.xCoord, 2000000)) + SQUARE(" & y & " - ISNULL(tbl_Postcodes.yCoord, 200000))) / 1000 * 0.62 <=150)" & _
                  " ORDER BY Dist

And my attempt of the mysql:

SELECT DISTINCT(v2_dealers.ID), name, town, County, CAST(SQUARE('$x' IS NULL(tbl_postcodes.xCoord, 2000000)) + SQUARE('$y' IS NULL(tbl_postcodes.yCoord, 200000)) / 1000 * 0.62 AS Int) AS Dist
                  FROM v2_dealers INNER JOIN v2_dealerbrands ON v2_dealers.ID=v2_dealerbrands.dealer LEFT OUTER JOIN tbl_Postcodes ON v2_dealers.Postcode=tbl_Postcodes.PC
                  left join tbl_rvlibrary on v2_dealerbrands.make=tbl_rvlibrary.make
                  WHERE v2_dealers.status='OK' and v2_dealers.id in (select ds.dealer from v2_dealersites ds,v2_sites s where s.id=ds.site and url='$thissite')
                  and tbl_rvlibrary.rvid='$rvID'
                  AND (SQRT(SQUARE('$x' IS NULL(tbl_postcodes.xCoord, 2000000)) + SQUARE('$y' IS NULL(tbl_postcodes.yCoord, 200000))) / 1000 * 0.62 <=150)
                  ORDER BY Dist


This is the error I receive:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IS NULL(tbl_postcodes.xCoord, 2000000)) + SQUARE(792660 - IS NULL(tbl_postcodes.' at line 1

I have tried using IF NULL but still receive the same error.

Answer : Can not convert a mssql query to a mysql query

I would recommend getting site-to-site between branches as well as that would optimise network flow.  It won't bring the network down, just remove your static routes before you enable the new VPN and the router will handle the routing (sounds silly) between sites.  With setting up a route through head office means you're involving your head office connections unnecessarily for traffic that could just flow directly between the branches.

If you have Exchange servers at the branches for example then you could set up connectors between the two branches and e-mails between users in the branches won't need to go through head office.  Same would apply for VoIP calls if you have VoIP system, and so on.

Let us know how you get on.
Random Solutions  
 
programming4us programming4us