I have sql query like shown below the sql server says that their is error in HAVING and ORDER bY is their any error with syntax near HAVING and ORDER BY, can anyone help.
SELECT Id,
Name1,
ZipCode,
StreetName,
StreetNumber,
State1,
Lat,
Lng,
Keyword,
( 6371 * ACOS( COS( (12.925432/57.2958) ) * COS( (Lat/57.2958) ) * COS( ( Lng/57.2958 ) - (77.5940171/57.2958) ) + SIN( 12.925432/57.2958 ) * SIN( Lat/57.2958 ) ) ) AS distance
FROM Business_Details
HAVING (distance < 1.5) and (Keyword like '%plumber%')
ORDER BY distance ;
Use
wherehere instead ofhaving.havingis useful for narrowing conditions on aggregate values.whereis useful for narrowing conditions on un-aggregated data.Update
SQL Server is not MySQL, what works on one …
work
re-enginerred before it will work.
This should be what you need