Convert Access IIF To SQL Server Case

I am attempting to convert an access 2013 IIF() statement to a SQL Server 2008 case statement, but I am getting an error of

Msg 102, Level 15, State 1, Line 5
Incorrect syntax near ')'.

I am sure this stems from my incorrect conversion, but what must I do to properly convert this syntax?

Access

((val1*mk)+val1)+IIf(ffsaa="0",0,6) AS CC

SQL Attempt

((val1*mk)+val1)+case when ffsaa=0 then 0 else 6 end) AS CC

Upvotes: 0

Views: 87

Answers (2)

Pரதீப்
Pரதீப்

Reputation: 93744

You don't need Case statement at all. You are trying to add a value(ffsaa) to another computed value. 0 does not make any difference in addition unless you have a value other than 0

Select ((val1*mk)+val1) + ffsaa

Upvotes: 0

Gurwinder Singh
Gurwinder Singh

Reputation: 39507

You are missing a opening bracket at start of the case. Use:

((val1*mk)+val1)+(case when ffsaa=0 then 0 else 6 end) AS CC

Upvotes: 2

Related Questions