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
触发器的创建
最新推荐文章于 2023-09-22 09:22:48 发布