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 2008 Forums
 Transact-SQL (2008)
 DELETE THE RECORDS BASED ON DATECOLUMN

Author  Topic 

kond.mohan
Posting Yak Master

213 Posts

Posted - 2012-11-22 : 08:34:34
Dear all
we are fething the from orcle to sql server loading on daily basis.(incremental process) here i am fetching the last 2 days records based on thethis sql statement

select * from abc where timestamp >=SYSDATE-3--1200 records are loaded(using ssis package source and destination)

here we need to delete the timestampcolumn-3 days records
i have provided below delete statement this is effetcing 0 records

DELETE FROM abc WHERE TIMEstamp =timestamp-3 (means last 3 days)

pls provide the way how to delete based on timestamp column

thanks

masterdineen
Aged Yak Warrior

550 Posts

Posted - 2012-11-22 : 10:20:04
delete from abc where timestamp between dateadd(day,-3,getdate()) and getdate()
Go to Top of Page

masterdineen
Aged Yak Warrior

550 Posts

Posted - 2012-11-22 : 10:40:28
second thoughts
you'd better use this one.

delete from abc
where timestamp between dateadd(day, datediff(day, 0, (getdate())), -3)
and dateadd(day, datediff(day, 0, (getdate())), -0)

that way you will include all records on the three days instead of exactly 3 days

Go to Top of Page

kond.mohan
Posting Yak Master

213 Posts

Posted - 2012-11-23 : 02:49:34
dear masterdineen
thx for your reply,
case 1. source table having modified then we need to follow the modified_date column for fetching the data .
case 2. source table doesn't have the modified_date column in this case which way we need to follow the fetch incremental data pls provide the samples

thanks
Go to Top of Page
   

- Advertisement -