SELECT IIF((Value = 25 and type like 'ar') or (total=55)', 1, 0) AS APR, *
FROM Spend
Case statement to for a table with and or conditions?
https://stackoverflow.com/questions/22162182
Question
I have a table name
Spend:
id value type date total
1 21 ar 3/3/2012 45
2 24 az 3/3/2012 55
3 25 az 3/3/2012 55
4 25 az 3/3/2012 45
5 25 ar 3/3/2012 45
Condition: APR=(value=25 and type like 'ar') or(total=55)
How can i write case statement in select statement with out using #temp and cte's in single select statement.
The output of select statement must be
id value type date total APR
1 21 ar 3/3/2012 45 0
2 24 az 3/3/2012 55 1
3 25 az 3/3/2012 55 1
4 25 az 3/3/2012 45 0
5 25 ar 3/3/2012 45 1
OTHER TIPS
Try this
SELECT id,value,type,date,total,APR,
CASE WHEN (value=25 and type like 'ar') OR (total=55) Then 1 ELSE 0 END AS [Apr]
FROM Table1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow