troubleshooting Question

MSSQL Join - Incorrect Syntax near the keyword 'where'

Avatar of Nico2011
Nico2011Flag for United Kingdom of Great Britain and Northern Ireland asked on
ASPMicrosoft SQL Server 2008
5 Comments1 Solution821 ViewsLast Modified:
Hello Experts,

I have an issue with the foillowing MSSQL Query, which returns the error below - it is a rather complex query (in my opinion!), but I need to link it to a booking calendar so we only get properties with availability showing...:

select * from (select row_number() over (order by distance) rn, * from (select * from (SELECT ID as XID, PayMonthly, ccaccepted, pool, sattv, disabled_access, internet, restaurants, shops, beach, golf, skiing, tennis, hiking, for_rent, for_sale, price_low, rental_currency, rental_USD, rental_EUR, rental_GBP, Problem, Property_Name, Town, Region, Property_Type, Property_Description, short_description, bedrooms, sleeps, photo, photo_two, photo_three, thumb, lat, lng, (3960 * acos( cos( radians(43.64701) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(7.00241) ) + sin( radians(43.64701) ) * sin( radians( lat ) ) ) ) AS distance FROM Villas) v WHERE for_rent = 1 AND Problem = 0 AND distance <= 10 AND price_low IS NOT NULL) q) x JOIN Diary on XID = Diary.PropID where NOT(StartDate between '7-Jan-2012' and '28-Jul-2012')
Microsoft OLE DB Provider for SQL Server

 error '80040e14'

Incorrect syntax near the keyword 'where'.

/villa-results-list.asp, line 112

THANKS in advance.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros