Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 SSIS and Import/Export (2012)
 Import documents into SQL using SSIS

Author  Topic 

alanmac
Starting Member

26 Posts

Posted - 2014-06-03 : 08:26:54
Hi,

In my database table I have 2 columns. One holds the path to a file (FileName), and the other is for the file itself. What I need to do is read each FileName from the database, then go to the location and read that file into the database as an image by updating the current row.

Does anyone know of a resource that explains how to do this? I feel I'm getting close but the updated rows each have null values for the image.

Thanks in advance.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-06-03 : 08:32:15
[code]DECLARE @SQL NVARCHAR(MAX);

SELECT @SQL = N'UPDATE mt
SET MyColumn = w.Content
FROM dbo.MyTable AS mt
CROSS JOIN OPENROWSET(BULK ' + QUOTENAME(MyPathColumn, N'''') + ', SINGLE_BLOB) AS w(Content)
WHERE mt.ID = ' + CAST(MyRowID AS NVARCHAR(12)) + ';'
FROM dbo.MyTable
WHERE MyRowID = 2;

EXEC (@SQL);[/code]


Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

alanmac
Starting Member

26 Posts

Posted - 2014-06-03 : 09:09:57
Thanks for that, but it didn't work. The record I specified still has a null value for the image column.

Would there be a way to do this through an SSIS package? This is for a colleague who has been asked to design one to perform this task.
Go to Top of Page
   

- Advertisement -