select d.*, x.*
from
(select row_number() over (order by v.distance) rn, v.*
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
WHERE for_rent = 1
AND Problem = 0
AND price_low IS NOT NULL
) AS v
WHERE v.distance <= 10
) AS x
JOIN (select Diary.PropID, row_number() over (order by v.PropID) rn
from Diary
where Diary.StartDate not between '7-Jan-2012' and '28-Jul-2012'
group by Diary.PropID
) as d
on x.XID = d.PropID and d.rn = 1
(select Diary.PropID -- min/max/count.....
from Diary
where Diary.StartDate not between '7-Jan-2012' and '28-Jul-2012'
group by Diary.PropID)
ASKER
ASKER
ASKER
ASKER
and d.rn=1
ASKER
ORDER BY x.distance
select x.*
from
(.... ) AS x
where not exists (select 1
FROM Diary
WHERE Diary.PropID = x.XID
AND Diary.StartDate not between '7-Jan-2012' and '28-Jul-2012'
)
ORDER BY x.distance
AND Diary.StartDate not between @DateFrom and @DateTo
ASKER
ASKER
ASKER
Active Server Pages (ASP) is Microsoft’s first server-side engine for dynamic web pages. ASP’s support of the Component Object Model (COM) enables it to access and use compiled libraries such as DLLs. It has been superseded by ASP.NET, but will be supported by Internet Information Services (IIS) through at least 2022.
TRUSTED BY
SELECT locationid, MIN(eventname) AS EventName, MIN(location_name) as LocationName
FROM dbo.event
WHERE (startdate >= '1/1/2012') AND (enddate <= '2/1/2012')
GROUP BY locationid
This will display the location ID, Location Name and Event Name and list the locationid only once. Notice what is the where clause does not have to show up in the results.