0

i ve some images in my database (type = image). i want to export them to my system disk as jpg file. i tried following codes, and im getting errors like this:

result

Where am I doing wrong?

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  
alexkidd
  • 68
  • 1
  • 9
  • Look into the marked duplicate or into [this answer](http://stackoverflow.com/a/12723149/5089204). You'll need a format file. – Shnugo Feb 10 '17 at 11:54
  • I'd suggest to start a new question. Try to create a minimal runnable example (e.g. no variables) to reproduce your issue. And please tell us the error you get... *I'm getting new error* is not enough :-) – Shnugo Feb 10 '17 at 12:55

0 Answers0