I need to insert into new table (2 columns) Distinct description from other table and in second row case.
So like:
Insert into @Temp1
Select distinct description from Table1,
CASE
WHEN aaa then 1
When bbb then 2
END
So basically for every inserted value in first column, in second column goes one of several possible values, depending on first value.
Is this possible?
Yes this is possible. Looks like you are missing the
input_expressionfrom your Simple CASE expression and have theFROMin the wrong place..Of course if
aaaetc are constants rather than derived from other columns inTable1such that the second column can be deterministically derived from the first column (and it isn’t going to be altered in future updates) there might not be any point in storing it at all. You can define the table variable with a computed column definition or simply use theCASEexpression whenSELECT-ing from it.Example of the computed column case