title: Inserting a pdf file to SQL table using SQL
body: <p>I am trying to insert a pdf file into a sql table (varbinary column)</p>
  
  <pre><code>create table pdfTest(pdfData varbinary(max))
  declare @filePath varchar(100)
  set @filePath = 'c:\pdfSample.pdf'
  INSERT INTO pdfTest (pdfData) SELECT * FROM OPENROWSET(BULK @filePath, SINGLE_BLOB) AS BLOB
  </code></pre>
  
  <p>However this gives an error</p>
  
  <pre><code> Incorrect syntax near '@filePath'.
  </code></pre>
  
  <p>None of the following assignment works</p>
  
  <pre><code> set @filePath = 'c:'\pdfSample.pdf'
   set @filePath = 'c:\\pdfSample.pdf'
  </code></pre>
  
  <p>But the following syntax works</p>
  
  <pre><code> INSERT INTO pdfTest (pdfData) SELECT * FROM OPENROWSET(BULK 'c:\pdfSample.pdf', SINGLE_BLOB) AS BLOB
  </code></pre>
  
  <p>Just wondering how @filePath can be used in the insert statement?</p>
  
  <p>Thank you</p>