Reputation: 109
I have this code in my C# application:
EmployeeFirstName = gc.Key.CommissionType.GetValueOrDefault() == CommissionTypeTypes.Personal ? gc.Select(ec => ec.EmployeeFirstName).FirstOrDefault() : string.Empty, //c.EmployeeFirstName,
and I want to have it in SQL
That means if my column "CommissionType" is the char 'P', take the value from EmployeeFirstName (and connect it), if not, make it null.
Columns are: EmployeeFirstName, CommissionType.
Upvotes: 0
Views: 142
Reputation: 33581
You can't have IF-ELSE in a view. It is a single select statement. But you could use a case expression for this.
case when CommisionType = 'P' then EmployeeFirstName end
Upvotes: 4
Reputation: 156998
Try a case
statement:
case
when CommissionType = 'P'
then EmployeeFirstName
else null -- you can leave this one out but put it there for clarity
end
EmployeeFirstName
Upvotes: 4