Hi, I'm using bcp to queryout images from database and T-SQL code looks something like this:
DECLARE c1 CURSOR FOR
SELECT (KeyField)
FROM (Table)
WHERE ...
OPEN c1
FETCH NEXT FROM c1
INTO @KeyField
WHILE @@FETCH_STATUS = 0
BEGIN
-- Create unique name for the file using KeyField from the table
SELECT @FileName = '(Server path ending with \)' + convert(varchar(18), @KeyField) + '.(ext)'
SET @bcpCommand = 'bcp "SELECT (image) FROM (Table) WHERE KeyField = ' + convert(varchar(18), @KeyField) + '" queryout "'
SET @bcpCommand = @bcpCommand + @FileName + '" -S (ServerName) -T -n'
EXEC master..xp_cmdshell @bcpCommand, no_output
FETCH NEXT FROM c1
INTO @KeyField
END
CLOSE c1
DEALLOCATE c1