title: Convert Varchar to Ascii
body: <p>I'm trying to convert the contents of a VARCHAR field to be unique number that can be easily referenced by a 3rd party.</p>
  
  <p>How can I convert a varchar to the ascii string equivalent? In TSQL? The ASCII() function converts a single character but what can I do to convert an entire string?</p>
  
  <p>I've tried using </p>
  
  <pre><code>CAST(ISNULL(ASCII(Substring(RTRIM(LTRIM(PrimaryContactRegion)),1,1)),'')AS VARCHAR(3))
  + CAST(ISNULL(ASCII(Substring(RTRIM(LTRIM(PrimaryContactRegion)),2,1)),'')AS VARCHAR(3))
  </code></pre>
  
  <p>....but this is tedious, stupid looking, and just doesn't really work if I had long strings.  Or if it is better how would I do the same thing in SSRS?</p>