Updated: 27 August 2010
Use HEX2OCT to convert a hexadecimal number to octal.
Syntax
SELECT [wctEngineering].[wct].[HEX2OCT] (
   <@Number, nvarchar(4000),>
 ,<@Places, float,>)
Arguments
@Number
is the hexadecimal number you want to convert. @Number cannot contain more than 10 characters. The most significant bit of @Number is the sign bit (40th bit from the right). The remaining 39 bits are magnitude bits. Negative numbers are represented using two's-complement notation. @Number is an expression of type float or of a type that can be implicitly converted to float. 
@Places
The number of characters to use. If @Places is NULL, HEX2OCT uses the minimum number of characters necessary. @Places is useful for padding the return value with leading 0s (zeros). @Places is an expression of type float or of a type that can be implicitly converted to float. 
Return Types
varchar(4000)
Remarks
·         If @Number is less than FFE0000000 or @Number is greater than 1FFFFFFF, HEX2OCT returns an error.
·         If @Number is negative, HEX2OCT ignores places and returns a 10-character octal number.
·         If @Number is not a valid hexadecimal number, HEX2OCT returns an error.
·         @Places is truncated to zero decimal places.
Examples
select wct.HEX2OCT('F',8)
This produces the following result
-------------------------
 
00000017
 
(1 row(s) affected)
select wct.HEX2OCT('B7',NULL) 
This produces the following result
-------------------------
 
267
 
(1 row(s) affected)
select wct.HEX2OCT('FFFFFFFFFF',NULL) 
This produces the following result
-------------------------
7777777777
 
(1 row(s) affected)