如果我必须按照您的要求做,我的包裹看起来像这样(减去第一步)
在下面创建 2 个名为和对象类型的变量
数据流如下所示。一般来说,我讨厌在数据流中聚合,但在这里它是有道理的。将您的数据写入文件,并找出您使用的 10 个文件名。将这些名称写入内存记录集对象 (TableList)。
使用 Recordset 对象并将其切碎(将 Jamie Thomson 的帖子合并为详细信息),这将帮助您将行从 RS 对象中提取出来。在 ForEach 循环中,您将执行一条 UPDATE 语句以将这些文件标记为已处理。
我使用以下脚本创建了一些数据
IF NOT EXISTS
(
SELECT *
FROM sys.tables AS T
WHERE T.name = 'Chunks' AND T.schema_id = SCHEMA_ID('dbo')
)
BEGIN
-- Source table
CREATE TABLE
dbo.Chunks
(
SourceFile varchar(50) NOT NULL
, JobDone bit NULL
, FileData varchar(500) NOT NULL
);
-- add some data
WITH SRC AS
(
SELECT
OBJECT_NAME(AC.object_id) AS SourceFile
, NULL AS bit
, AC.name AS FileData
FROM
sys.all_columns AS AC
)
, TOP60 AS
(
SELECT TOP 60
SRC.SourceFile
, COUNT(1) AS rc
FROM
SRC
GROUP BY
SRC.SourceFile
ORDER BY
2 DESC
)
INSERT INTO
dbo.Chunks
(
SourceFile
, JobDone
, FileData
)
SELECT
SRC.SourceFile
, SRC.bit
, SRC.FileData
FROM
TOP60 T
INNER JOIN
SRC
ON SRC.SourceFile = T.SourceFile;
END
我的 OLEDB 源看起来像以下查询
-- grab all the data associated to them
SELECT
C.SourceFile
, C.JobDone
, C.FileData
FROM
dbo.Chunks AS C
WHERE
C.SourceFile IN
(
-- Grab any 10 sourcefile names that haven't been processed
SELECT TOP 10
C.SourceFile
FROM
dbo.Chunks AS C
WHERE
C.JobDone IS NULL
)
ORDER BY
C.SourceFile;
我的更新声明看起来像
UPDATE
C
SET
JobDone = 1
FROM
dbo.Chunks AS C
WHERE
C.JobDone IS NULL
AND C.FileName = ?;