Daniel Bailey
Daniel Bailey

Reputation: 115

Changing when to if statement in SQL server

How do I change the following code to an if statement that returns a boolean 0 or 1 value? My end results I would like to have, is one column listing the interest rate of 2, and my results column with a 0 or 1 if the condition is true.

(Case when new_interestratevariability = 2
and (new_interestrateindex = 1 or new_interestrateindex = 2 or new_interestrateindex = 3 or new_interestrateindex = 4 or new_interestrateindex = 6)
    and new_crms_dt = @Curr_Date
    then 0 else 1 end) as CIEDIT_VAL_96,

Currently, I am getting something like below:

Results Table

Upvotes: 0

Views: 56

Answers (2)

Degan
Degan

Reputation: 989

To filter rows, use a Where clause. The Case statement in the Select clause will modify the value shown on the row.

Select *
from table
Where new_interestratevariability = 2
      and new_interestrateindex IN (1,2,3,4,6)
      and new_crms_dt = @Curr_Date

Upvotes: 1

Daniel Bailey
Daniel Bailey

Reputation: 115

Found my answer, it was as simple as adding "not in" instead of just "in". Thanks everyone

(Case when new_interestratevariability = 2
and (new_interestrateindex not in(1,2,3,4,6))
    and new_crms_dt = @Curr_Date
        then 1 else 0 end) as CIEDIT_VAL_96,

Upvotes: 0

Related Questions