Is there a shortcut in MS SQL Server for a call CASE WHEN bit THEN 'something' ELSE null END ? Is there a way to write it differently?
DECLARE @data TABLE(IsSomething BIT NOT NULL, Value NVARCHAR(30) NOT NULL);
INSERT INTO @data VALUES
CASE WHEN IsSomething = 1 THEN Value ELSE NULL END,
CASE WHEN IsSomething = 1 THEN 'string' ELSE NULL END,
CASE WHEN IsSomething = 0 THEN 'not ' + Value ELSE NULL END
I am especially looking for the variant where the BIT value is 1 (true).
The concern is readability of the select statement and excesively long expression to write for a simple case/if.
I use those expressions in one of my views where it bothers me the most. I am not saying the design of that view or the tables is ideal. (In fact, it is not ideal!)