"格式文件无法打开" BCP导出后出错

时间:2017-02-10 11:35:17

标签: sql-server database windows-10 sql-server-2014 bcp

我的数据库中有一些图像(type = image)。我想将它们作为jpg文件导出到我的系统磁盘。我尝试了以下代码,我得到这样的错误:

result

我在哪里做错了?

CREATE PROCEDURE [dbo].[ImgExport] 
@OutputFilePath VARCHAR(500) = 'C:\RES\'
AS
BEGIN
DECLARE @totrow int
DECLARE @currow int
DECLARE @result int
DECLARE @nsql nvarchar(4000)
DECLARE @sqlStatements table (ID int IDENTITY(1, 1),  SqlStatement varchar(max))   

INSERT
INTO @sqlStatements
SELECT 'BCP "SELECT Pic FROM [lptdata].[dbo].[Imagefiles] WHERE  NAME = '''
+ CAST(NAME AS VARCHAR(500)) + '''" queryout ' + @OutputFilePath 
+ CAST(NAME AS VARCHAR(500)) + '.jpg -T -f C:\RES\Images.fmt'
FROM dbo.Imagefiles

SET @totrow = @@ROWCOUNT
SET @currow = 1
WHILE @totrow > 0 and @currow <= @totrow
BEGIN
SELECT @nsql = SqlStatement
FROM @sqlStatements
WHERE ID = @currow
EXEC @result = xp_cmdshell @nsql
SET @currow = @currow + 1
END
END  

0 个答案:

没有答案