Dear all, I would like to create unique HTML color codes (like "#CC9900" used in a SSRS report) for my databases: First (poor) attempt: SELECT databases.name ,SUBSTRING(HASHBYTES('SHA1', databases.name), 1, 3) Result FROM sys.databases Better idea? Thanks!
Figured out by myself now: ALTER FUNCTION [dbo].[HtmlColorCode] ( @String NVARCHAR(MAX) ) RETURNS TABLE AS RETURN ( SELECT '#' + UPPER(RIGHT(master.dbo.fn_varbintohexstr(SUBSTRING(HASHBYTES('SHA1', @String), 1, 3)), 6)) AS HtmlColorCode ) Like it?
It looks like your existing idea is reasonable. To be honest, the main pitfall I can see in your method here is that you may get some very similar colours coming out. But this is always likely to be a risk if you dynamically generate the colours from data in sys.databases The only other thought I could offer is to create a static table somewhere with columns for database name and colour code and manage it manually