DECLARE @IntVal int SELECT @IntVal = 24 SELECT '0x' + SUBSTRING( HexStr , ( @IntVal / POWER( 16 , 7 ) ) % 16 + 1 , 1 ) + SUBSTRING( HexStr , ( @IntVal / POWER( 16 , 6 ) ) % 16 + 1 , 1 ) + SUBSTRING( HexStr , ( @IntVal / POWER( 16 , 5 ) ) % 16 + 1 , 1 ) + SUBSTRING( HexStr , ( @IntVal / POWER( 16 , 4 ) ) % 16 + 1 , 1 ) + SUBSTRING( HexStr , ( @IntVal / POWER( 16 , 3 ) ) % 16 + 1 , 1 ) + SUBSTRING( HexStr , ( @IntVal / POWER( 16 , 2 ) ) % 16 + 1 , 1 ) + SUBSTRING( HexStr , ( @IntVal / POWER( 16 , 1 ) ) % 16 + 1 , 1 ) + SUBSTRING( HexStr , ( @IntVal / POWER( 16 , 0 ) ) % 16 + 1 , 1 ) AS HexVal FROM ( SELECT '0123456789ABCDEF' AS HexStr ) AS a
CREATE TABLE #t ( IntVal int , HexStr AS ( '0x' + SUBSTRING( '0123456789ABCDEF' , ( IntVal / POWER( 16 , 7 ) ) % 16 + 1 , 1 ) + SUBSTRING( '0123456789ABCDEF' , ( IntVal / POWER( 16 , 6 ) ) % 16 + 1 , 1 ) + SUBSTRING( '0123456789ABCDEF' , ( IntVal / POWER( 16 , 5 ) ) % 16 + 1 , 1 ) + SUBSTRING( '0123456789ABCDEF' , ( IntVal / POWER( 16 , 4 ) ) % 16 + 1 , 1 ) + SUBSTRING( '0123456789ABCDEF' , ( IntVal / POWER( 16 , 3 ) ) % 16 + 1 , 1 ) + SUBSTRING( '0123456789ABCDEF' , ( IntVal / POWER( 16 , 2 ) ) % 16 + 1 , 1 ) + SUBSTRING( '0123456789ABCDEF' , ( IntVal / POWER( 16 , 1 ) ) % 16 + 1 , 1 ) + SUBSTRING( '0123456789ABCDEF' , ( IntVal / POWER( 16 , 0 ) ) % 16 + 1 , 1 ) ) );
INSERT INTO #t VALUES( 13 ); INSERT INTO #t VALUES( 11345 ); INSERT INTO #t VALUES( 721024 ); INSERT INTO #t DEFAULT VALUES;
SELECT * FROM #t;
|