Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
HelloNeed 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?!!ThanksNew 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 NULLSELECT [Before] = COUNT(*) FROM TableName WHERE DataDados < (DATEADD(Day,-5,GETDATE()))SELECT [After] = COUNT(*) FROM TableName WHERE DataDados >= (DATEADD(Day,-5,GETDATE()))
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
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 bothNew one :)