Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Delete where date <= @paramDate

Author  Topic 

Zath
Constraint Violating Yak Guru

298 Posts

Posted - 2009-09-15 : 13:16:40
This has to do with milliseconds

First, I get the MAX date:

	SELECT MAX(CreatedDate) FROM Imports 
WHERE importcode = 0


.Net will bring it back as 9/15/2009 1:04:02 PM
In query analyzer, it will be something like 2009-09-15 13:04:02.920

The .920 is more acurate.

Then, I import another file, get the MAX date again (if exists) as @PendingCreateDate

And need to delete the older records so....

	DELETE FROM Imports
WHERE importcode = 0 AND CreatedDate <= @PendingCreateDate


The problem is, if two files are imported back to back, the time stamp is not acurate enough for this to work.

Or there's something else I'm missing.

Thanks,

Zath

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-09-15 : 13:52:20
One possibility would be to create an SP that does the comparison (and the delete) in the database.
Another is to google ".net datetime milliseconds" becuase I'm sure there are ways to compare to the millisecond in .net.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -