title: SQL Server convert hexadecimal varchar value to INT
body: <p>I created a T-SQL function</p>
  
  <pre><code>CREATE FUNCTION dbo.GetDecimalFromHexa (@HexValue VARCHAR(10))
  RETURNS INT
  BEGIN
     IF (CHARINDEX('0x',@HexValue) = 0)
        SET @HexValue = '0x' + @HexValue
     RETURN CONVERT(INT, @HexValue )    
  END
  </code></pre>
  
  <p>Then I call my function like that</p>
  
  <pre><code>SELECT dbo.GetDecimalFromHexa ('0000385A')
  </code></pre>
  
  <p>I get an error:</p>
  
  <blockquote>
    <p>Conversion failed when converting the varchar value '0x0000385A' to data type int.</p>
  </blockquote>
  
  <p>Please correct me.</p>
  
  <p>[Edit]<br>
  I want to get int output</p>