SO3087921

0

Please login or register to vote for this query.

(click on this box to dismiss)

Mathematics

Q&A for people studying math at any level and professionals in related fields

-- SO3087921

DECLARE @temp AS TABLE (hex char(6)) 
 
INSERT  INTO @temp 
VALUES  ('200000') -- Should convert to Red: 51 Green: 51 Blue: 204 
 
DECLARE @table AS varchar(16) 
SET @table = '0123456789abcdef' 
 
SELECT  hex 
       ,16 * (CHARINDEX(SUBSTRING(hex, 1, 1), @table) - 1) + (CHARINDEX(SUBSTRING(hex, 2, 1), @table) - 1) AS R 
       ,16 * (CHARINDEX(SUBSTRING(hex, 3, 1), @table) - 1) + (CHARINDEX(SUBSTRING(hex, 4, 1), @table) - 1) AS G 
       ,16 * (CHARINDEX(SUBSTRING(hex, 5, 1), @table) - 1) + (CHARINDEX(SUBSTRING(hex, 6, 1), @table) - 1) AS B 
FROM    @temp

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results