Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools


Click here to copy the following block
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
-- Output of SELECT statement:
/*
HexVal  
----------
0x00000018
*/


-- SQL70 / 2000 only
-- Using a computed column in a table
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;
-- Output
/*
IntVal   HexStr  
----------- ----------
   11345 0x00002C51
   721024 0x000B0080
NULL    NULL
     13 0x0000000D
*/


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.