https://pastein.ru/t/bRv

  скопируйте уникальную ссылку для отправки


--shelf_life_dc 
select * from shelf_life_dc where item = '3980314' and dc = '353' and lot = '0000700921';

--item 
select * from item where code = '3980314';

--dc 
select * from dc where code = '353';

--osg 
select * from osg where 
exp_from <= (select total_shelf_life from shelf_life_dc where item = '3980314' and dc = '353' and lot = '0000700921')
and exp_to >= (select total_shelf_life from shelf_life_dc where item = '3980314' and dc = '353' and lot = '0000700921')
and (item = '3980314' or (ui4 = (select ui4 from item where code = '3980314') and item = '' )) 
and dest = '353';

--sourcing 
select distinct(dc1) from sourcing where item = '3980314' and (dc1 = '353' or dc2 = '353');