ALTER TABLE AKUZ.T_TICKET ADD "epgutype" integer NULL;

UPDATE AKUZ.T_TICKET t
SET "epgutype" = (
	case e.entname
		when 'PRIMARY_TICKET' then 2
		when 'DISPANSERISATION_TICKET' then 7
		when 'TELECONSULTATION_TICKET' then 11
		when 'QUARTZ_TICKET' then 3
		when 'WORKBREAK_TICKET' then 3
		when 'OTHER_FREETIME_TICKET' then 3
		else 9 
	end)
from VCLib.t_entities e
where t.type_ = e.entityid;


ALTER TABLE AKUZ.T_TICKET ALTER COLUMN "epgutype" SET NOT NULL;


-- Tables

-- Alters

ALTER TABLE AKUZ.T_SCHEDULE_ITEM_TICKET ADD "epgutype" integer NULL;

UPDATE AKUZ.T_SCHEDULE_ITEM_TICKET
SET "epgutype" = (
	case TicketType
		when 1 then 2
		when 9 then 7
		when 8 then 11
		when 3 then 3
		when 4 then 3
		when 5 then 3
		else 9 
	end);


ALTER TABLE AKUZ.T_SCHEDULE_ITEM_TICKET ALTER COLUMN "epgutype" SET NOT NULL;

