title: T-SQL Convert Hex to decimal
body: <p>I try to use TSQL and I get some problem to convert hex to decimal when the value is inside a variable.</p>
  
  <p>My code is:</p>
  
  <pre><code>SET @hex = SUBSTRING(@x,1,2) --give 1e
  SET @hex = '0x' + @hex
  SELECT CAST (@hex AS int)
  </code></pre>
  
  <p>I get the error that the conversion failed when converting the varchar value to int</p>
  
  <p>I don't know what it's wrong and so far I can't find solution</p>
  
  <p>Any idea? Thanks</p>