Wednesday, February 25, 2015

Convert/Insert all files in a directory

Refer the below sql, we can collect the file name into a temporary table and use in the subsequent statement to convert into the image into binary data.



DECLARE @folder varchar(500) = 'C:\testing'
DECLARE @DOSCommand varchar(1024); SET @DOSCommand = 'dir ' + @folder +'\' + ' /A-D /B'
IF OBJECT_ID('tempdb..#myFileList') IS NOT NULL DROP TABLE #myFileList
CREATE TABLE #myFileList (FileNumber INT IDENTITY,[FileName] VARCHAR(256))
INSERT INTO #myFileList([FileName]) EXEC MASTER.dbo.xp_cmdshell @DOSCommand

SELECT * FROM #myFileList where fileName is not null

DROP TABLE #myFileList





Regards, RSingh



No comments:

Post a Comment