title: Convert HEX value to CHAR on DB2
body: <p>In connection with data replication from <code>SQL Server</code> to <code>DB2</code> I have the following question:</p>
  
  <p>On <code>DB2</code> I have a table containing (for simplicity) two columns: <code>COL1</code> and <code>COL2</code>.</p>
  
  <p><code>COL1</code> is defined as <code>CHAR(20)</code>. <code>COL2</code> is defined as <code>CHAR(10)</code>.</p>
  
  <p><code>COL1</code> is replicated from SQL by converting a string into hex, e.g. <code>"abcdefghij"</code> to <code>"6162636465666768696A"</code> or <code>"1111111111"</code> to <code>"31313131313131313131"</code> by using the following SQL query:</p>
  
  <pre><code>CONVERT(char(20), cast(@InputString as binary) 2)
  </code></pre>
  
  <p>where <code>@InputString</code> would be <code>"abedefghij"</code>.</p>
  
  <p>In other words COL1 contains the hex value, but as a string (sorry if the wording is incorrect).</p>
  
  <p>I need to convert the hex value back to a string and put this value into <code>COL2</code>.</p>
  
  <p>What should the SQL query be on <code>DB2</code> to do the convertion? I know how to do this on <code>SQL Server</code>, but not on <code>DB2</code>.</p>
  
  <p>Note: The reason the hex-value is not pre-fixed with <code>"0x"</code> is because style 2 is used in the <code>CONVERT</code> statement.</p>