View Single Post
Old 05-26-2006, 11:23 AM   #7 (permalink)
leftwingx
Upright
 
Location: Calgary, AB
To clarify further my code in SQL using memory tables would look like this (note: I'm using the @dates mem table to simulate your actual data table):

Code:
DECLARE @dates TABLE (OrigDate SMALLDATETIME)

INSERT INTO @dates (OrigDate) VALUES ('01/01/2003')
INSERT INTO @dates (OrigDate) VALUES ('01/15/2003')
INSERT INTO @dates (OrigDate) VALUES ('02/26/2003')
INSERT INTO @dates (OrigDate) VALUES ('02/27/2003')

DECLARE @d1 TABLE (ID INT IDENTITY, Date1 SMALLDATETIME)
DECLARE @d2 TABLE (ID INT IDENTITY, Date2 SMALLDATETIME)

INSERT INTO @d1 (Date1)
SELECT OrigDate [d1] FROM @dates WHERE OrigDate NOT IN (SELECT MIN(OrigDate) FROM @dates)
INSERT INTO @d2 (Date2)
SELECT OrigDate [d2] FROM @dates WHERE OrigDate NOT IN (SELECT MAX(OrigDate) FROM @dates)

SELECT *
FROM @dates
WHERE OrigDate IN (
			SELECT TOP 1
				Date1
			FROM @d1 t1
				INNER JOIN @d2 t2
					ON t1.ID = t2.ID
			WHERE DATEDIFF(DAY,Date2,Date1) > 30
			ORDER BY Date1 DESC)
__________________
Happiness is just a roughing penalty away.

Last edited by leftwingx; 05-26-2006 at 11:25 AM.. Reason: Forgot to remove check selects
leftwingx is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73