1

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.

  • 1
    In my experience with OPENROWSET, the FILE_PATH must be hard-coded, and not be a derived value from a table or even stored in a variable. I an no longer positive of this (it was SQL 2005) which is why I am merely making a comment not an answer. – datagod May 14 '14 at 11:31
  • 2
    It's not going to work that way without using dynamic SQL. See stackoverflow.com/questions/6935598/…. – SQLFox May 14 '14 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.