title: Hexadecimal valued string to varbinary SQL Server 2008
body: <p>I have a string with a hexadecimal value, as an example, like so: <code>"AD5829FC..."</code> which is a varbinary I took and saved in hexadecimal to a text file. The thing is, I need to get this back to a varbinary by running an insert query through C# and SQL Server 2008. </p>
  
  <p>How do I get it back to its original format. I am currently using a SQL CAST like so: </p>
  
  <pre><code>CAST('HEX VALUE' AS varbinary(MAX))
  </code></pre>
  
  <p><strong>NOTE:</strong> I need to save it to the text file like I just showed it so that the CSV doesn't get any \n or comma characters from a sequence in the hexadecimal</p>