Reputation: 51
I will like to add a column to an existing table using a derived column. Is this possible?
However the new column N
will be conditional. For example, when column A = 1
and column B <> 2
then it's value will be 1
and when Column A = 2
and Column B = 1
then 2
. When column A = 3
then the value is 0
, otherwise 4
.
Upvotes: 1
Views: 211
Reputation: 1913
You can use a ? : construction in a Derived Column to create a conditionally filled column: http://msdn.microsoft.com/en-us/library/ms141680.aspx
Upvotes: 0
Reputation: 6395
UPDATE Test set N =
case
when A = 1 and B != 2 then 1
when A = 2 and B = 2 then 2
when A = 3 then 0
else 4
end
Upvotes: 0
Reputation: 10875
You can derive the column but to insert it into a table it should already exist in that target table. So the short answer is no, it's not possible.
Upvotes: 2