title: Convert hex into a string
body: <p>I am converting a string in VBScript Classic ASP into hex like the following:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Function StringToHex(ByRef pstrString)
      Dim llngIndex
      Dim llngMaxIndex
      Dim lstrHex
      llngMaxIndex = Len(pstrString)
      For llngIndex = 1 To llngMaxIndex
          lstrHex = lstrHex &amp; Right("0" &amp; Hex(Asc(Mid(pstrString, llngIndex, 1))), 2)
      Next
      StringToHex = lstrHex
  End Function
  </code></pre>
  
  <p>When I pass a string for example "<code>moe</code>", I get "<code>6D6F65</code>"</p>
  
  <p>Now I am trying to convert this hex back to string using stored procedure in SQL Server like the following:</p>
  
  <pre><code>convert(nvarchar, convert(varbinary, @Param,2))
  </code></pre>
  
  <p>but it is getting converted to the wrong string in Chinese.</p>