Reputation: 99
Based on one column within my query results (Value), I am trying to write an if/else statement based on the value held which will display the result the in an additional row.
For example, if I have a record of 2 within the value field, but I want to check whether it is above < 5. If the value is less than 5 I basically want the additional column to display a hardcoded value of 5, else display actual value.
Any help would be appreciated.
Upvotes: 1
Views: 21376
Reputation: 11195
Use a case
statement
select a.*,
case
when a.TheField < 5 then 5
else a.TheField
end as NewField
from MyTable a
Upvotes: 5
Reputation: 204766
You can use a case
select value, case when value < 5
then 5
else value
end as calculated_column
from your_table
Upvotes: 0