I need a Sql Query for below requirement
If the value is >= 5 and <=60, then no change is required
If the value < 5 then override the value with 5
If the value is > 60 then override the value with 60
I need a Sql Query for below requirement
If the value is >= 5 and <=60, then no change is required
If the value < 5 then override the value with 5
If the value is > 60 then override the value with 60
Try this
Update table
set col1 = case when (col1 >=5 and col1 <=60) then col1
when col1 < 5 then 5
else 60
end
make sure data type of col1 is integer.
do you want to update the underlying table or do you want to query the underlying table?
create table #savi(id int, propertyname varchar(50), propertyscore int)
insert into #savi
select 1, 'Lexx ', 1 union
select 1, 'Altair IV', 5 union
select 1, 'Anarres', 6 union
select 1, 'Arrakis ', 59 union
select 1, 'Athas', 1 union
select 1, 'Andromeda', 60 union
select 1, 'Stargate', 1000
SELECT case
when propertyscore between 5 and 60 then propertyscore
when propertyscore < 5 then 5
when propertyscore > 60 then 60
else propertyscore
end changepropertyscore,
propertyscore,
propertyname
from #savi
drop table #savi