触发器的创建

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER workSheetTigger
   ON  [dbo].[Table_Html]
   AFTER INSERT
AS
declare @endDate date
declare @tableName varchar(255)
declare @taskId varchar(100)
declare @province varchar(255)
declare @storedDate date
declare @dbNum int
declare @cycle varchar(255)
declare @startDate date
 select @endDate=GETDATE()
 select @tableName=Table_Name from inserted
 select @province='002'
 select @storedDate=stored_time from OPENQUERY (ORCL,'select * from WORK_SHEET2') where Table_Name=@tableName and PROVINCE=@province
 select @dbNum=COUNT(*) FROM [dbo].[Table_Html]  WHERE Insert_Date >= @storedDate and Table_Name=@tableName
 select @cycle=release_frequency from OPENQUERY (ORCL,'select * from WORK_SHEET2') where Table_Name=@tableName and PROVINCE=@province 
if(@cycle='001')
begin
select @startDate=DATEADD(dd,180,@storedDate)
end
if(@cycle='002')
begin
select @startDate=DATEADD(dd,90,@storedDate)
end
if(@cycle='003')
begin
select @startDate=DATEADD(dd,365,@storedDate)
end
if(@cycle='004')
begin
select @startDate=DATEADD(dd,1,@storedDate)
end
if(@cycle='006')
begin
select @startDate=DATEADD(dd,30,@storedDate)
end
if(@startDate<=@endDate)
BEGIN
 SET NOCOUNT ON;
 INSERT INTO OPENQUERY(ORCL,'SELECT * FROM WORK_SHEET_LOG') (table_name,db_number,insert_date,TASK_ID,PROVINCE) VALUES(@tableName,@dbNum,@endDate,@taskId,@province)
    UPDATE OPENQUERY(ORCL,'select * from WORK_SHEET2') SET stored_time=@endDate where Table_Name=@tableName and PROVINCE=@province
END
GO

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值