83
формирования актов результатов медико-экономической экспертизы или
экспертизы качества, задавая соответствующий параметр,
например[46.стр.205]:
/* CtrlStP(quAct2) */
declare @KodLPU smallint, @godEx smallint, @mesEx tinyint, @Ex tinyint
select @KodLPU = :KodLPU, @godEx = :godEx, @mesEx = :mesEx, @Ex = :Ex
--select @KodLPU = 8685, @godEx = 2009, @mesEx = 6, @Ex = 1
--select @KodLPU = 218, @godEx = 2010, @mesEx = 05, @Ex = 0
if exists( select * from vw_mesExAdd EK where Kod_LPU=@KodLPU
and godEx = @godEx and mesNum = @mesEx and Ex = @Ex
)
select * from (
select datename(month,s.period)+' '+convert(char(4),year(s.period))as nam_Ree,
right(convert(varchar(8),s.period,4),5) as period, EK.NumRee as Ree,
r5.Num_PP, r5.DaySt, r5.Nozo, r5.Tarif as TarifLPU,
case isNull(r5.Day_opl,0) when 0 then convert(numeric(8,2),0) else
convert(numeric(8,2),r5.sum_before/r5.Day_opl)end as TarifOpl,--t.summa as
TarifSK,
r5.Ukdl, r5.S_day, r5.Day_opl, d.Name_otd, p.Prof_name,
ex2.Kod_Otd as Otd, ex2.Profil as Prof, ex2.UKDL_Ex, ex2.day_ex,
case isNull(ex2.day_ex,0) when 0 then convert(numeric(8,2),0) else
convert(numeric(8,2),ex2.Sum_Ex/ex2.day_ex)end as tarif_ex,
ex2.Sum_Ex as ExK, r5.sum_before as Opl, f2.fio_Ex,
r5.family, convert(varchar(8),r5.date_R,4) as date_R, r5.Polis_Num,
ltrim(isNull(sh.punkt,'-')) as punkt,
isNull(sh2.Sum_Shtr,convert(numeric(12,2),0)) as Sum_Shtr,
convert(varchar(180),r5.note) as note
from vw_mesExAdd EK
inner join Reestr r5 (nolock) on r5.Num_PP=EK.Num_PP and r5.NumRee=EK.NumRee
inner join Expert ex2 (nolock) on --ex2.Num_Exp=isNull(r5.Num_Ex,0)
ex2.NumRee=EK.NumRee and ex2.Num_PP=EK.Num_PP
left outer join ExpShtr sh2 (nolock) on sh2.Num_Exp=ex2.Num_Exp
left outer join Shtraf sh (nolock) on sh.num_punkt=sh2.num_punkt
inner join FIO_Exp f2 (nolock) on f2.Num_Ex=isNull(r5.Num_Ex,0)
inner join SpisRee s (nolock) on s.NumRee=r5.NumRee
left outer join departLPU d (nolock) on d.kod_otd=r5.kod_otd and
d.Kod_LPU=@KodLPU
left outer join profil p (nolock) on p.profil=r5.profil
where EK.Kod_LPU=@KodLPU
and godEx = @godEx and mesNum = @mesEx and Ex = @Ex
union
select datename(month,s.period)+' '+convert(char(4),year(s.period))as nam_Ree,
right(convert(varchar(8),s.period,4),5) as period, EK.NumRee as Ree,
r5.Num_PP, r5.DaySt, r5.Nozo, r5.Tarif as TarifLPU,
case isNull(r5.Day_opl,0) when 0 then convert(numeric(8,2),0) else
convert(numeric(8,2),r5.sum_before/r5.Day_opl)end as TarifOpl,--t.summa as
TarifSK,
r5.Ukdl, r5.S_day, r5.Day_opl, d.Name_otd, p.Prof_name,
ex2.Kod_Otd as Otd, ex2.Profil as Prof, ex2.UKDL_Ex, ex2.day_ex,
case isNull(ex2.day_ex,0) when 0 then convert(numeric(8,2),0) else
convert(numeric(8,2),ex2.Sum_Ex/ex2.day_ex)end as tarif_ex,
ex2.Sum_Ex as ExK,
case when EK.Num_PP in (select Num_PP from Expert ex3(nolock)
where ex3.NumRee=EK.NumRee and ex3.Num_PP=EK.Num_PP)
then 0 else r5.sum_before end as Opl,
f2.fio_Ex, r5.family, convert(varchar(8),r5.date_R,4) as date_R,
r5.Polis_Num,
ltrim(isNull(sh.punkt,'-')) as punkt,
isNull(sh2.Sum_Shtr,convert(numeric(12,2),0)) as Sum_Shtr,
convert(varchar(180),r5.note) as note
from vw_mesExAdd EK
inner join Reestr r5 (nolock) on r5.Num_PP=EK.Num_PP and r5.NumRee=EK.NumRee
inner join AddExpert ex2 (nolock) on
ex2.NumRee=EK.NumRee and ex2.Num_PP=EK.Num_PP
left outer join ExpShtr sh2 (nolock) on sh2.Num_Exp=ex2.Num_Exp
left outer join Shtraf sh (nolock) on sh.num_punkt=sh2.num_punkt