--
-- ### Case when in update
-- 
-- 
--

drop if exists table erp_disk;
create table erp_disk ( dskid int, wwn string(100), sid string(10), location string(10) );

drop if exists view erp_diskview;
create view erp_diskview as
select
erp_disk.dskid as dskid,
erp_disk.wwn as wwn,
case when substr(erp_disk.wwn,20,1) = '1' then 'MD' else 'GV' end  as location,
erp_disk.sid as sid
from
erp_disk;

insert into erp_disk values ( 2, '60000743267843211111288', 'PUG', null);
insert into erp_disk values ( 2, '60000743268767868768798', 'PUG', null);
insert into erp_disk values ( 2, '60000743268324329999298', 'PUG', null);

select * from erp_diskview;

select count(*), location, sid from erp_diskview group by location, sid;

update erp_disk set location = case when wwn = '1' then 'MD' else 'GV' end;

select * from erp_disk;

