INSERT INTO ISZL.T_MKB_NAMED_RANGE
           (MkbNamedRangeID
           ,Name
           ,MkbFrom
           ,MkbTo)
SELECT
           gen_random_uuid()--<MkbNamedRangeID, uniqueidentifier,>
          ,'Подлежащие ДН'--<Name, varchar(100),>
          ,m.MCBCode--<MkbFrom, varchar(10),>
          ,m.MCBCode--<MkbTo, varchar(10),>)
from ISZL.T_DN_PERIODICITY p
    join ISZL.T_MKB m on m.MkbID = p.Mkb
group by m.MCBCode;

INSERT INTO ISZL.T_DN_PERIODICITY_MKB_RANGES
           (DnPeriodicityMkbRangesID
           ,DnPeriodicity
           ,MkbNamedRange)
SELECT
           gen_random_uuid()--<DnPeriodicityMkbRangesID, uniqueidentifier,>
          ,p.ID--<DnPeriodicity, uniqueidentifier,>
          ,r.MkbNamedRangeID--<MkbNamedRange, uniqueidentifier,>)
from ISZL.T_DN_PERIODICITY p
    join ISZL.T_MKB m on m.MkbID = p.Mkb
    join ISZL.T_MKB_NAMED_RANGE r on r.MkbFrom = m.MCBCode
where r.Name = 'Подлежащие ДН';
