SAMPLE For SQL query records within a range of boundaries and max/min outside the range

0

Please login or register to vote for this query.

(click on this box to dismiss)

http://stackoverflow.com/questions/6311566/sql-query-records-within-a-range-of-boundaries-and-max-min-outside-the-range

GIS

Q&A for cartographers, geographers and GIS professionals

DECLARE @START_DATE datetime
DECLARE @END_DATE datetime
SET @START_DATE = '2010-10-20'
SET @END_DATE = '2010-11-01'


SELECT score, 
       creationdate 
FROM   posts 
WHERE  creationdate BETWEEN (SELECT TOP 1 creationdate 
                             FROM   posts 
                             WHERE  creationdate < @START_DATE 
                             ORDER  BY creationdate DESC) 
                             AND 
                                   (SELECT TOP 1 creationdate 
                                    FROM   posts 
                                    WHERE  creationdate > @END_DATE 
                                    ORDER  BY creationdate ASC) 
ORDER by creationDate

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results
:records returned in :time ms:cached