title: SQL Server convert from varbinary to varchar
body: <p>I have been banging my head against a wall on this. I am trying to get data from a field in a SQL Server database that has a type of <code>varbinary(28)</code>.</p>
  
  <p>I just can't work out how to convert the data from hex back to chars.</p>
  
  <p>I know that a column = '1081X' and the hex stored in the database is <code>0x7E959C9ABB818C</code>.</p>
  
  <p>I have tried: </p>
  
  <pre><code>SELECT
      0x7E959C9ABB818C, '1081X',
      CONVERT(VARBINARY(28), '1081X'),
      CONVERT(VARBINARY(28), N'1081X')
  
  -- 0x7E959C9ABB818C 1081X   0x3130383158    0x31003000380031005800
  </code></pre>
  
  <p>Any ideas on how to retrieve '1081X' from the code 0x7E959C9ABB818C ?</p>