NB: This answer was based on the first incarnation of the question. The same general principles apply to the revised version, so I did not update the column names to synchronize them.
@ n8wrl raises a good question in the comments, but to answer your question (assuming the color and text are character data and therefore do not need casting).
I also suggested that non-columns are NULL. If they are then joined NULL , you will get NULL if you have ANSI default parameters. If this is not the desired behavior, you will need to use ISNULL(color,'') , etc.
DECLARE @example table ( id int NOT NULL, color char(6) NOT NULL, text varchar(100) NOT NULL ) insert into @example SELECT 01, '990000', 'Red' UNION ALL SELECT 02, '009900', 'Green' UNION ALL SELECT 03, '000099', 'Blue' UPDATE @example SET text = '<span style=''color: #' +color+'''>' +text+'</span>' SELECT * FROM @example
I have to say that I doubt that storing it in this format is a good idea. This means that you will store a lot of redundant characters, which means that fewer lines will fit into the data page and more I / O and less efficient use of memory.
Martin smith
source share