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?
-
19-10-2022 - |
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
La solution 2
Autres conseils
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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow