无法检索文件夹中的pdf文件的大小

时间:2013-07-24 13:11:17

标签: sql sql-server sql-server-2008 tsql sql-server-2008-r2

无法检索文件夹中pdf文件的大小,下面的代码会在表格中返回一个空列,我还想知道是否可以将文件名和大小都存储在一个表中。< / p>

  Create table #PDFFiles

(
            PDFFile varchar(300)
)

Declare @param as varchar(100)
Declare @Path as varchar(1000)
Declare @PreparedBatch as Nvarchar(max);

Set @PreparedBatch =
            'DECLARE @pdf pdf
            SELECT @pdf = CAST(BulkColumn AS pdf)
            FROM OPENROWSET(BULK ''?'', SINGLE_BLOB) AS x
            INSERT dbo.PDFDocument (PDFdoc)
                        SELECT @pdf;';
 Set @Path = 'C:\dump\'
Set @param = 'dir ' + @Path + '*.pdf /b'

Insert into #PDFFiles
Exec master..xp_cmdshell @param
Update #PDFFiles Set PDFFile = @Path + PDFFile


While Exists(select * from #PDFFiles where PDFFile is not null)
Begin
            Declare @CurrentFile Table (PDFFile varchar(300));

            Delete Top (1) from #PDFFiles
            OUTPUT DELETED.PDFFile INTO @CurrentFile
            Where PDFFile is not null

            Declare @Batch as Varchar(max)
            Select @Batch = Replace(@PreparedBatch,'?',PDFFile)  from @CurrentFile    
            Exec (@Batch)
            Delete from @CurrentFile
End  

这是我在运行此代码时遇到的错误

Column, parameter, or variable #1: Cannot find data type pdf.
Parameter or variable '@pdf' has an invalid data type.

1 个答案:

答案 0 :(得分:0)

没有pdf数据类型:

DECLARE @pdf pdf

那应该是VARBINARY或FILESTREAM

Which data-type for storing images and documents in SQL Server 2005