Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Selecting dates not in a date set
Message
From
19/07/2007 16:01:21
John Baird
Coatesville, Pennsylvania, United States
 
 
To
19/07/2007 16:00:58
John Baird
Coatesville, Pennsylvania, United States
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01241975
Message ID:
01242126
Views:
25
>>I dunno if it's better or not but here's another way
>>DECLARE @DateBegin datetime, @DateEnd datetime
>>SET @DateBegin = '20060101'
>>SET @DateEnd   = '20070719'
>>
>>CREATE TABLE #Trans (Fund char(3), TransDate datetime)
>>INSERT INTO #Trans VALUES ('ABC','20060101')
>>INSERT INTO #Trans VALUES ('ABC','20070602')
>>INSERT INTO #Trans VALUES ('ABC','20070603')
>>INSERT INTO #Trans VALUES ('ABC','20070615')
>>
>>INSERT INTO #Trans VALUES ('DEF','20070705')
>>INSERT INTO #Trans VALUES ('DEF','20070706')
>>INSERT INTO #Trans VALUES ('DEF','20070708')
>>INSERT INTO #Trans VALUES ('DEF','20070711')
>>
>>SELECT ISNULL(t1.Fund, t2.Fund) AS Fund,
>>		DATEADD(dd,1, ISNULL(t1.TransDate, @DateBegin-1)) AS bd,
>>		DATEADD(dd, -1, ISNULL(t2.TransDate, @DateEnd+1)) AS ed
>>	FROM #trans t1
>>	FULL JOIN #trans t2
>>		ON t2.Fund = t1.Fund AND t2.TransDate > t1.TransDate
>>			AND t1.TransDate BETWEEN @DateBegin AND @DateEnd
>>			AND t2.TransDate BETWEEN @DateBegin AND @DateEnd
>>	WHERE DATEDIFF(dd, ISNULL(t1.TransDate, @DateBegin-1), ISNULL(t2.TransDate, @DateEnd+1)) > 1


Thanks to all
>>		AND NOT EXISTS ( SELECT * FROM #Trans
>>			WHERE Fund = ISNULL(t1.Fund, t2.Fund)
>>				AND TransDate > ISNULL(t1.TransDate, @DateBegin-1)
>>				AND TransDate < ISNULL(t2.TransDate, @DateEnd+1))
>>ORDER BY 1, 2	
>>
>>DROP TABLE #Trans	
>>
>>
>>>I have an accounting table with transactions entered daily for funds. I need to select from the transaction table to make sure all dates have been loaded. I need to check that every day from 9/1/2006 thru today are represented in the file for all funds, and print a list of the missing days, i.e.
>>>
>>>
>>>fund         trans_date
>>>ABC           10/14/06
>>>ABC            3/14/07
>>>DEF            1/4/07
>>>
>>>
>>>
>>>I have been going round and round with this. I'm not sure the best way to implement it. How would you do it?
Previous
Reply
Map
View

Click here to load this message in the networking platform