title: How to script VARBINARY to copy it from one DB to another using a script?
body: <p>I need to generate an SQL insert script to copy data from one SQL Server to another.
  So with .net, I'm reading the data a given SQL Server table and write this to a new text file which can then be executed in order to insert this data on other databases.</p>
  
  <p>One of the columns is a VARBINARY(MAX).<br>
  How should and can I transform the obtained byte[] into text for the script so that it can still be inserted on the other databases?</p>
  
  <p>SSMS shows this data as hex string. Is this the format to use?
  I can get this same format with the following</p>
  
  <pre><code>BitConverter.ToString(&lt;MyByteArray&gt;).Replace("-", "")
  </code></pre>
  
  <p>But how can this be inserted again?<br>
  I tried</p>
  
  <pre><code>CONVERT(VARBINARY(MAX), "0xMyHexString")
  </code></pre>
  
  <p>This does an insert, but the value is not the same as in the source table.</p>