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 From Scripting Help

Author  Topic 

ostinoh
Yak Posting Veteran

66 Posts

Posted - 2013-07-23 : 12:12:48
Hello –
I currently have an SSIS package running and the first part of it deletes all data in (Table A) but saves the rows with the PIT of Friday at 4:00 PM for reference reasons.

DELETE FROM dbo.BackLogLaborOld
WHERE (datename(dw,PIT)<>'Friday' or datepart(hh,PIT) <> 16)

Now they want to change the day and time to Saturday at 12:00 PM to save but don't want to have the script delete all data from the past Friday’s at 4:00 PM data.

So I want to save the old Friday data but going forward change to the new day and time.

Could anyone suggest how I would go about doing that? Is that possible?

Regards,
David

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-07-23 : 13:05:40
Like this:
DELETE FROM dbo.BackLogLaborOld
WHERE (datename(dw,PIT)<>'Saturday' or datepart(hh,PIT) <> 12)
AND PIT > '20130722';
That 'Saturday' is language dependent, so if you have any need for internationalization/localization, instead of datename(dw,PIT)<>'Saturday' use DATEDIFF(dd,0,PIT)%7 <> 5
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-24 : 01:32:26
quote:
Originally posted by ostinoh

Hello –
I currently have an SSIS package running and the first part of it deletes all data in (Table A) but saves the rows with the PIT of Friday at 4:00 PM for reference reasons.

DELETE FROM dbo.BackLogLaborOld
WHERE (datename(dw,PIT)<>'Friday' or datepart(hh,PIT) <> 16)

Now they want to change the day and time to Saturday at 12:00 PM to save but don't want to have the script delete all data from the past Friday’s at 4:00 PM data.

So I want to save the old Friday data but going forward change to the new day and time.

Could anyone suggest how I would go about doing that? Is that possible?

Regards,
David


its possible if you've a batchid which indicates the batch which processed the records. Or you could also capture this information if you've an audit or control table setup which logs details on each package processed records.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

ostinoh
Yak Posting Veteran

66 Posts

Posted - 2013-07-24 : 12:08:18
Thank you all for the responses. I will try and post with my results when we try it out.

Regards,
David
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-25 : 00:48:56
quote:
Originally posted by ostinoh

Thank you all for the responses. I will try and post with my results when we try it out.

Regards,
David


welcome
let us know how you got on

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -