user3782929
user3782929

Reputation: 51

Derived column add conditional column

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

Answers (3)

Joost
Joost

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

Metaphor
Metaphor

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

Jayvee
Jayvee

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

Related Questions