I have a directory with images and a table in my DB with the path of each file. The main application allow me to create reports where I can display an image, so I was thinking to use a query like:
SELECT [ID] ,[PT_CODE] ,[FILE_PATH], CASE WHEN [FILE_PATH] IS NOT NULL THEN (SELECT * FROM OPENROWSET(BULK [FILE_PATH], SINGLE_BLOB) TT) END AS IMAGE_LOADED FROM [DB].[dbo].[TABLE_MR_FILES]
But I keep getting the error:
Incorrect syntax near 'FILE_PATH'.
I have try multiple combinations without luck to make the OPENROWSET read the path stored in the column [FILE_PATH]. What am I missing?
Note: I am using MSSQL 2012. I don't want to import the images into the DB just load them in the fly as needed by the report runned from the application. I have full access to the DB so if a store procedure is the solution I can go with it.