SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 DELETE THE RECORDS BASED ON DATECOLUMN
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kond.mohan
Posting Yak Master

India
189 Posts

Posted - 11/22/2012 :  08:34:34  Show Profile  Reply with Quote
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

Edited by - kond.mohan on 11/22/2012 08:36:25

masterdineen
Aged Yak Warrior

United Kingdom
548 Posts

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

masterdineen
Aged Yak Warrior

United Kingdom
548 Posts

Posted - 11/22/2012 :  10:40:28  Show Profile  Reply with Quote
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

India
189 Posts

Posted - 11/23/2012 :  02:49:34  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000