Reputation: 67
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
Upvotes: 3
Views: 74
Reputation: 437
SELECT IIF((Value = 25 and type like 'ar') or (total=55)', 1, 0) AS APR, *
FROM Spend
Upvotes: 1
Reputation: 28413
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
Upvotes: 3