Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2008 如何更改包内的查询以使用作业的最后执行日期时间?_Sql Server 2008_Ssis - Fatal编程技术网

Sql server 2008 如何更改包内的查询以使用作业的最后执行日期时间?

Sql server 2008 如何更改包内的查询以使用作业的最后执行日期时间?,sql-server-2008,ssis,Sql Server 2008,Ssis,我有一个日常作业,它运行SSIS包,使用日期范围从表中选择前一天的记录数。我想将其更改为每隔几分钟运行一次,因此我需要将上一次运行查询中使用的datetime保存到一个变量中,并将该变量存储在另一个DB表中。有人建议我使用IO存储它,但不确定这是什么意思 SELECT [authorUrl],[postDate] ,[dateadded] FROM [Feeds].[dbo].[XMLFeed] where CONVERT(DATE, DateAdded) = DATEADD(DAY, -1,

我有一个日常作业,它运行SSIS包,使用日期范围从表中选择前一天的记录数。我想将其更改为每隔几分钟运行一次,因此我需要将上一次运行查询中使用的datetime保存到一个变量中,并将该变量存储在另一个DB表中。有人建议我使用IO存储它,但不确定这是什么意思

SELECT [authorUrl],[postDate] ,[dateadded]
FROM [Feeds].[dbo].[XMLFeed]
where CONVERT(DATE, DateAdded) = DATEADD(DAY, -1, CONVERT(DATE, SYSDATETIME()))
order by dateadded desc

如何将where语句更改为where dateadded等于或大于上次运行此select的时间。

必须将上次执行值存储在表中的某个位置。首先,创建一个表来保存最后的执行参数:

create table LastExecutionParameters
(
  Id int identity(1,1) not null,
  LastExecutionDate datetime
)
然后,这样使用它:

declare @executionDate datetime = 
    (select top 1 DateAdd(Day, 1, LastExecutionDate) 
       from LastExecutionParameters 
      order by Id desc);

SELECT [authorUrl],[postDate] ,[dateadded]
FROM [Feeds].[dbo].[XMLFeed]
where CONVERT(DATE, DateAdded) = DATEADD(DAY, -1, @executionDate)
order by dateadded desc

insert into LastExecutionParameters values (@executionDate);
当然,可以根据需要更改
dateadd
调用