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 2000 Forums
 Transact-SQL (2000)
 [RESOLVED] - Delete Dates

Author  Topic 

mickey_pt
Starting Member

6 Posts

Posted - 2010-07-13 : 11:02:56
Hello

Need help with one simple delete query...
I have this:
DELETE FROM TableName WHERE DataDados >= (DATEADD(Day,-5,GETDATE()))

The DataDados column it's a SMALLDATETIME, and when i run this query all my rows are deleted?!!

Thanks

New one :)

Kristen
Test

22859 Posts

Posted - 2010-07-13 : 11:06:13
Seems improbable

That does this give you?

SELECT [All] = COUNT(*) FROM TableName WHERE DataDados IS NOT NULL
SELECT [Before] = COUNT(*) FROM TableName WHERE DataDados < (DATEADD(Day,-5,GETDATE()))
SELECT [After] = COUNT(*) FROM TableName WHERE DataDados >= (DATEADD(Day,-5,GETDATE()))
Go to Top of Page

SD_Monkey
Starting Member

38 Posts

Posted - 2010-07-13 : 11:09:24
TRY this one....


DELETE FROM TableName
WHERE DataDados in(SELECT DataDados FROM TableName
WHERE DataDados >=(DATEADD(dd,-5,GETDATE()))


A maze make you much more better
Go to Top of Page

mickey_pt
Starting Member

6 Posts

Posted - 2010-07-13 : 11:13:21
Oh sorry...
Just understand what i was doing wrong.
Wrong column to compare, this column always have the same date for all rows. :(:(:(

Thanks to both

New one :)
Go to Top of Page

SD_Monkey
Starting Member

38 Posts

Posted - 2010-07-13 : 11:16:58
ITS Ok




A maze make you much more better
Go to Top of Page
   

- Advertisement -