我的数据库中有许多 pdf 文件,我想根据优先级将它们存储在一个文件夹中。当我使用下面的代码时,我无法保存所有文件;它只保存一个文件。:(
Declare
@File_Path_1 VARBINARY(MAX),
@FileName_1 VARCHAR(MAX),
@Timestamp_1 varchar(max),
@objectToken_1 int
DECLARE cFiles CURSOR FAST_FORWARD FOR
SELECT request_number from data where priority=1
OPEN cFiles
FETCH NEXT FROM cFiles INTO @FileName_1
WHILE @@FETCH_STATUS = 0 BEGIN
SET @FileName_1 = @FileName_1
set @Timestamp_1='c:\Dump\1.pdf'
EXEC sp_oacreate 'ADODB.Stream', @ObjectToken_1 OUTPUT
EXEC sp_oasetproperty @objecttoken_1, 'type', 1
EXEC sp_oamethod @objecttoken_1,'open'
EXEC sp_oamethod @objecttoken_1,'Write',Null,@File_Path_1
EXEC sp_oamethod @objecttoken_1,'Savetofile',Null,@Timestamp_1,2
EXEC sp_oamethod @objecttoken_1,'Close'
EXEC sp_oamethod @objecttoken_1,'open'
FETCH NEXT FROM cFiles INTO @FileName_1
END
CLOSE cFiles
DEALLOCATE cFiles
上面的代码只为我获取了一条记录,任何人都可以帮忙