Hello,
I'm working on a DB on which I can run only SELECT commands, so I'd
like to modify this UPDATE command, which makes use of CASE:
update Table
set field2 = case
when (SUBSTR(field,1 ,2) in ('01','02','05' )) then 1
when (SUBSTR(field,1 ,2) in ('15','16')) then 2
when (SUBSTR(field,1 ,2) in ('18','19','22' ,'36') or SUBSTR(field,1, 3)
in ('174','175','1 77','244','245' ,'297','323','3 34','335')) then 3
else 0
end;
I've modified it into this:
select *,
case
when (SUBSTR(field,1 ,2) in ('01','02','05' )) then 1
when (SUBSTR(field,1 ,2) in ('15','16')) then 2
when (SUBSTR(field,1 ,2) in ('18','19','22' ,'36') or SUBSTR(field,1, 3)
in ('174','175','1 77','244','245' ,'297','323','3 34','335')) then 3
else 0
end
as field2
from Table
But it doesn't work properly, because it always returns 0.
So I thought to change it into this:
select *,
case SUBSTR(field,1, 2)
when '01' then '1'
when '02' then '1'
when '05' then '1'
when '15' then '2'
when '16' then '2'
when '18' then '3'
when '19' then '3'
when '22' then '3'
when '36' then '3'
else 0
end
as field2
from Table
But, in this way, I only check 2 chars values, even if I need to check
3 chars values too...
How can I do? Have you got any idea?
Thank you very much in advance
Cheers
Carmelo
I'm working on a DB on which I can run only SELECT commands, so I'd
like to modify this UPDATE command, which makes use of CASE:
update Table
set field2 = case
when (SUBSTR(field,1 ,2) in ('01','02','05' )) then 1
when (SUBSTR(field,1 ,2) in ('15','16')) then 2
when (SUBSTR(field,1 ,2) in ('18','19','22' ,'36') or SUBSTR(field,1, 3)
in ('174','175','1 77','244','245' ,'297','323','3 34','335')) then 3
else 0
end;
I've modified it into this:
select *,
case
when (SUBSTR(field,1 ,2) in ('01','02','05' )) then 1
when (SUBSTR(field,1 ,2) in ('15','16')) then 2
when (SUBSTR(field,1 ,2) in ('18','19','22' ,'36') or SUBSTR(field,1, 3)
in ('174','175','1 77','244','245' ,'297','323','3 34','335')) then 3
else 0
end
as field2
from Table
But it doesn't work properly, because it always returns 0.
So I thought to change it into this:
select *,
case SUBSTR(field,1, 2)
when '01' then '1'
when '02' then '1'
when '05' then '1'
when '15' then '2'
when '16' then '2'
when '18' then '3'
when '19' then '3'
when '22' then '3'
when '36' then '3'
else 0
end
as field2
from Table
But, in this way, I only check 2 chars values, even if I need to check
3 chars values too...
How can I do? Have you got any idea?
Thank you very much in advance
Cheers
Carmelo
Comment