知行合一

博客园 首页 新随笔 联系 订阅 管理
/*
作用:归档3个月前的短信发送记录
创建人:zhuxiang
日期:2012-10-30
*/
ALTER Proc [dbo].[Sms_Job_History_Send]
As
Begin
	Declare @Temp table (MsgID varchar(20))
	Declare @Time datetime Set @Time = DateAdd(mm,-3,getdate())
	
	--检索出需要归档的记录
	Insert Into @Temp(MsgID)
	Select top 5000 MsgID From IB_Sms_Send_Bill(nolock) Where SubmitTime < @Time and State = 9
	
	--删除主表
	Delete a
	Output deleted.*
	Into ytFax_DB_History..IB_Sms_Send_Bill
	From IB_Sms_Send_Bill a,@Temp b
	Where a.MsgID = b.MsgID
	
	--删除明细表
	Delete a
	Output deleted.*
	Into ytFax_DB_History..IB_Sms_Send_Detail_Bill
	From IB_Sms_Send_Detail_Bill a,@Temp b
	Where a.MsgID = b.MsgID
End

 

posted on 2015-04-27 09:43  callbin  阅读(271)  评论(0编辑  收藏  举报