if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[DopProv]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
਍搀爀漀瀀 瀀爀漀挀攀搀甀爀攀 嬀搀戀漀崀⸀嬀䐀漀瀀倀爀漀瘀崀ഀഀ
GO
਍ഀഀ
SET QUOTED_IDENTIFIER ON 
਍䜀伀ഀഀ
SET ANSI_NULLS ON 
਍䜀伀ഀഀ

਍䌀刀䔀䄀吀䔀 瀀爀漀挀攀搀甀爀攀 䐀漀瀀倀爀漀瘀ഀഀ
  @D1 datetime,
਍  䀀䐀㈀ 䐀愀琀攀琀椀洀攀ഀഀ

਍愀猀 ഀഀ
declare 
਍  䀀䬀 昀氀漀愀琀Ⰰഀഀ
  @K1 int
਍⼀⨀猀攀琀 䀀搀㄀㴀✀㄀㄀⸀　㄀⸀㈀　㈀　✀ഀഀ
set @d2='11.29.2022'*/
਍猀攀琀 䀀欀㴀搀愀琀攀搀椀昀昀⠀洀漀渀琀栀Ⰰ䀀搀㄀Ⰰ䀀搀㈀⤀ഀഀ
 
਍猀攀氀攀挀琀   ㈀ 愀猀 瀀爀Ⰰ ⴀⴀ洀愀砀⠀焀⸀最爀漀瀀攀爀⤀ 愀猀 最爀漀瀀攀爀Ⰰ 洀愀砀⠀焀⸀椀搀瀀爀攀搀瀀爀⤀ 愀猀 椀搀瀀爀攀搀瀀爀Ⰰഀഀ
(case when  max(g.tipeanal)=1 then max(g.praprizschet) end) as idschetsubshetdtm,
਍⠀挀愀猀攀 眀栀攀渀  洀愀砀⠀最⸀琀椀瀀攀愀渀愀氀⤀㴀㈀ 琀栀攀渀 洀愀砀⠀最⸀瀀爀愀瀀爀椀稀猀挀栀攀琀⤀ 攀渀搀⤀ 愀猀 椀搀猀挀栀攀琀猀甀戀猀栀攀琀欀琀洀Ⰰഀഀ
min(case  when(g.KodSchetDT<10) then ('0'+ convert(varchar(3),g.kodschetdt)) else convert(varchar(3),g.kodschetdt)end  + case  when(g.kodsubschetdt<10) then ('0'+convert(varchar(3),g.kodsubschetdt)) else (convert(varchar(3),g.kodsubschetdt))end )  as dt2, 
਍洀椀渀⠀挀愀猀攀  眀栀攀渀⠀最⸀欀漀搀猀挀栀攀琀欀琀㰀㄀　⤀ 琀栀攀渀  ✀　✀⬀挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀挀栀攀琀欀琀⤀   攀氀猀攀 挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀挀栀攀琀欀琀⤀ 攀渀搀 ⬀ 挀愀猀攀  眀栀攀渀⠀最⸀欀漀搀猀甀戀猀挀栀攀琀欀琀㰀㄀　⤀ 琀栀攀渀 ⠀✀　✀⬀挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀甀戀猀挀栀攀琀欀琀⤀⤀ 攀氀猀攀 ⠀挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀甀戀猀挀栀攀琀欀琀⤀⤀攀渀搀 ⤀  愀猀 欀琀㈀ഀഀ
, sum( 
਍ऀ挀愀猀攀 眀栀攀渀 ⠀搀愀礀⠀焀⸀搀愀琀攀瘀瘀⤀㴀搀愀礀⠀䀀䐀㈀⤀⤀ 琀栀攀渀 ഀഀ
				(case when (q.idiznos in (2,4,5,7)) then (q.SumIzn*q.KolfM) 
਍ऀऀऀऀ  眀栀攀渀 ⠀焀⸀椀搀椀稀渀漀猀 㴀 ㌀ ⼀⨀⨀⼀愀渀搀 ⠀爀漀甀渀搀⠀䀀欀Ⰰ㈀⤀ⴀ㄀⤀㴀　⼀⨀⨀⼀⤀ 琀栀攀渀 ⠀焀⸀挀栀攀渀愀⼀㈀⨀焀⸀䬀漀氀昀䴀⤀ ഀഀ
				  when (q.idiznos = 6 and (round(@k,2)-1)=1) then (q.SumIzn*q.KolfM)
਍ऀऀऀऀ  眀栀攀渀 ⠀焀⸀椀搀椀稀渀漀猀 㴀 㠀 ⼀⨀⨀⼀愀渀搀 ⠀爀漀甀渀搀⠀䀀欀Ⰰ㈀⤀ⴀ㄀⤀㴀　⼀⨀⨀⼀⤀ 琀栀攀渀 ⠀焀⸀匀甀洀䤀稀渀⨀焀⸀䬀漀氀昀䴀⤀ഀഀ
				  when (q.idiznos = 6 and (round(@k,2)-1)>1) then (q.chena-q.chena/2*0.02*q.KolfM)
਍ऀऀऀऀ 攀渀搀⤀ഀഀ
	 else 				
਍ऀऀऀऀ⠀挀愀猀攀 眀栀攀渀 ⠀焀⸀椀搀椀稀渀漀猀 椀渀 ⠀㈀Ⰰ㐀Ⰰ㔀Ⰰ㜀⤀⤀ 琀栀攀渀 ⠀焀⸀匀甀洀䤀稀渀⨀焀⸀䬀漀氀昀䴀⤀ഀഀ
				  when (q.idiznos = 3 and round(convert(int,@k),0)=0) then (q.chena/2*q.KolfM) 
਍ऀऀऀऀ  眀栀攀渀 ⠀焀⸀椀搀椀稀渀漀猀 㴀 㘀 愀渀搀 爀漀甀渀搀⠀挀漀渀瘀攀爀琀⠀椀渀琀Ⰰ䀀欀⤀Ⰰ　⤀㴀㄀⤀ 琀栀攀渀 ⠀焀⸀匀甀洀䤀稀渀⨀焀⸀䬀漀氀昀䴀⤀ഀഀ
				  when (q.idiznos = 8 and round(convert(int,@k),0)=0) then (q.SumIzn*q.KolfM)
਍ऀऀऀऀ  眀栀攀渀 ⠀焀⸀椀搀椀稀渀漀猀 㴀 㘀 愀渀搀 爀漀甀渀搀⠀挀漀渀瘀攀爀琀⠀椀渀琀Ⰰ䀀欀⤀Ⰰ　⤀㸀㄀⤀ 琀栀攀渀 ⠀焀⸀挀栀攀渀愀ⴀ焀⸀挀栀攀渀愀⼀㈀⨀　⸀　㈀⨀焀⸀䬀漀氀昀䴀⤀攀渀搀⤀  攀渀搀ഀഀ
     ) as itog
਍昀爀漀洀ഀഀ
(select max(d.idgroperm)as idgroperm,max(SprMolM.idpredpr) as idpredpr , case  when (d.idsklm=1) then (CONVERT(varchar(3),g.KodSchetkT) +'.'+CONVERT(varchar(3),g.KodSubSchetkT) ) else  (CONVERT(varchar(3),g.KodSchetdT) +'.'+CONVERT(varchar(3),g.KodSubSchetdT)) end as groper,max(s.datem)as datem, max(s.idiznos)as idiznos,max(SprMolM.fio)as fio,max(s.datevv)as datevv, max(d.kodsklm)as kodsklm, max(s.dateOI)as dateOI, max(s.sumizn)as sumizn, max(s.kolfm)as kolfm, max(s.edizmer)as edizmer, max(s.artm)as artm , max(s.pntm)as pntm,max(NameVidTovM)as nametov,max(cenom) as chena , sum(s.kolfm) as kol  
਍昀爀漀洀 猀琀爀椀渀最洀愀氀漀挀 猀Ⰰ 搀漀挀洀愀氀漀挀 搀Ⰰ 匀瀀爀䴀漀氀䴀Ⰰ琀戀最爀漀瀀攀爀 最 ഀഀ
where s.iddocm=d.iddocm and d.viddocm=1 and SprMolM.kodsklm=d.kodsklm and d.idgroperm=g.idgroper and PrIznos=0 
਍ഀഀ
group by g.idgroper,s.datem,SprMolM.idpredpr,d.kodsklm,s.dateoi,case  when (d.idsklm=1) then (CONVERT(varchar(3),g.KodSchetkT) +'.'+CONVERT(varchar(3),g.KodSubSchetkT) ) else  (CONVERT(varchar(3),g.KodSchetdT) +'.'+CONVERT(varchar(3),g.KodSubSchetdT)) end,s.pntm,s.cenom
਍甀渀椀漀渀ഀഀ
select max(d.idgroperm)as idgroperm,max(SprMolM.idpredpr) as idpredpr,min( CONVERT(varchar(3),g.KodSchetkT) +'.'+CONVERT(varchar(3),g.KodSubSchetkT)) as groper,max(s.datem)as datem, max(s.idiznos)as idiznos, max(SprMolM.fio)as fio,max(s.datevv)as datevv, max(d.kodsklm)as kodsklm, max(s.dateOI)as dateOI, max(s.sumizn)as sumizn, max(s.kolfm)as kolfm, max(s.edizmer)as edizmer, max(s.artm)as artm, max(s.pntm)as art, max(NameVidTovM)as nametov,max(cenom) as chena , -1*sum(s.kolfm) as kol  
਍昀爀漀洀 猀琀爀椀渀最洀愀氀漀挀 猀Ⰰ 搀漀挀洀愀氀漀挀 搀Ⰰ 匀瀀爀䴀漀氀䴀Ⰰ琀戀最爀漀瀀攀爀 最 ഀഀ
where s.iddocm=d.iddocm and d.viddocm=2  and SprMolM.kodsklm=d.kodsklm and d.idgroperm=g.idgroper and PrIznos=0 
਍ഀഀ
group by  g.idgroper,s.datem,SprMolM.idpredpr,s.dateoi,d.kodsklm,CONVERT(varchar(3),g.KodSchetkT) +'.'+CONVERT(varchar(3),g.KodSubSchetkT),s.pntm,s.cenom )as q,tbndsiznos g
਍眀栀攀爀攀 ⠀焀⸀椀搀椀稀渀漀猀⤀㸀㄀ 愀渀搀ഀഀ
q.dateoi>=@d1 --convert(varchar(4),year(q.dateoi))+'.'+convert(varchar(2),month(q.dateoi))+'.01'>=convert(varchar(4),year(@d2))+'.'+convert(varchar(2),month(@d2))+'.01'
਍愀渀搀 焀⸀椀搀最爀漀瀀攀爀洀㴀最⸀椀搀最爀漀瀀攀爀  愀渀搀 最⸀瀀爀㴀㈀  ഀഀ
group by q.idgroperm,q.idpredpr
਍ഀഀ

਍甀渀椀漀渀 愀氀氀 ⴀⴀ㄀ഀഀ

਍猀攀氀攀挀琀 瀀爀 Ⰰ 挀愀猀攀 眀栀攀渀 ⠀最⸀琀椀瀀攀愀渀愀氀 椀渀 ⠀㄀Ⰰ㌀⤀⤀ 琀栀攀渀 最⸀瀀爀愀瀀爀椀稀猀挀栀攀琀 攀渀搀 愀猀 椀搀猀挀栀攀琀猀甀戀猀栀攀琀搀琀洀Ⰰ挀愀猀攀 眀栀攀渀 ⠀最⸀琀椀瀀攀愀渀愀氀㴀㈀⤀ 琀栀攀渀 最⸀瀀爀愀瀀爀椀稀猀挀栀攀琀 眀栀攀渀 ⠀最⸀琀椀瀀攀愀渀愀氀㴀㌀⤀ 琀栀攀渀 最⸀瀀爀愀瀀爀椀稀猀挀栀攀琀欀琀 攀渀搀 愀猀 椀搀猀挀栀攀琀猀甀戀猀栀攀琀欀琀洀Ⰰഀഀ
convert(varchar(3),g.kodschetdt)+case  when(g.kodsubschetdt<10) then '0'+convert(varchar(3),g.kodsubschetdt) else convert(varchar(3),g.kodsubschetdt)end as dt,convert(varchar(3),g.kodschetkt)+case  when(g.kodsubschetkt<10) then '0'+convert(varchar(3),g.kodsubschetkt) else convert(varchar(3),g.kodsubschetkt)end as kt,sum(sumndsm) -- IAN
਍昀爀漀洀 搀漀挀洀愀氀漀挀 搀㄀Ⰰ琀戀渀搀猀椀稀渀漀猀 最Ⰰ琀戀最爀漀瀀攀爀 最㈀ ⴀⴀ 䤀䄀一ഀഀ
where d1.datedocm between @D1 and @D2 
਍ 愀渀搀 瀀爀㴀㄀ 愀渀搀 最⸀椀搀最爀漀瀀攀爀㴀搀㄀⸀椀搀最爀漀瀀攀爀洀 愀渀搀 搀㄀⸀椀搀最爀漀瀀攀爀洀㴀最㈀⸀椀搀最爀漀瀀攀爀ഀഀ
group by pr,convert(varchar(3),g.kodschetdt)+case  when(g.kodsubschetdt<10) then '0'+convert(varchar(3),g.kodsubschetdt) else convert(varchar(3),g.kodsubschetdt)end,
਍         挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀挀栀攀琀欀琀⤀⬀挀愀猀攀  眀栀攀渀⠀最⸀欀漀搀猀甀戀猀挀栀攀琀欀琀㰀㄀　⤀ 琀栀攀渀 ✀　✀⬀挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀甀戀猀挀栀攀琀欀琀⤀ 攀氀猀攀 挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀甀戀猀挀栀攀琀欀琀⤀攀渀搀Ⰰഀഀ
case when (g.tipeanal in (1,3)) then g.praprizschet end,case when (g.tipeanal=2) then g.praprizschet when (g.tipeanal=3) then g.praprizschetkt end 
਍ഀഀ
union all-- 4,5,6
਍猀攀氀攀挀琀 瀀爀Ⰰ挀愀猀攀 眀栀攀渀 ⠀最⸀琀椀瀀攀愀渀愀氀 椀渀 ⠀㄀Ⰰ㌀⤀⤀ 琀栀攀渀 最⸀瀀爀愀瀀爀椀稀猀挀栀攀琀 攀渀搀 愀猀 椀搀猀挀栀攀琀猀甀戀猀栀攀琀搀琀洀Ⰰ挀愀猀攀 眀栀攀渀 ⠀最⸀琀椀瀀攀愀渀愀氀㴀㈀⤀ 琀栀攀渀 最⸀瀀爀愀瀀爀椀稀猀挀栀攀琀 眀栀攀渀 ⠀最⸀琀椀瀀攀愀渀愀氀㴀㌀⤀ 琀栀攀渀 最⸀瀀爀愀瀀爀椀稀猀挀栀攀琀欀琀 攀渀搀 愀猀 椀搀猀挀栀攀琀猀甀戀猀栀攀琀欀琀洀Ⰰഀഀ
convert(varchar(3),g.kodschetdt)+case  when(g.kodsubschetdt<10) then '0'+convert(varchar(3),g.kodsubschetdt) else convert(varchar(3),g.kodsubschetdt)end as dt,
਍挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀挀栀攀琀欀琀⤀⬀挀愀猀攀  眀栀攀渀⠀最⸀欀漀搀猀甀戀猀挀栀攀琀欀琀㰀㄀　⤀ 琀栀攀渀 ✀　✀⬀挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀甀戀猀挀栀攀琀欀琀⤀ 攀氀猀攀 挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀甀戀猀挀栀攀琀欀琀⤀攀渀搀 愀猀 欀琀Ⰰഀഀ
case when (pr=3) then sum(sumndsoo10m) when (pr=4) then sum(itogom) when (pr=5) then sum(sumndsm) when (pr=6) then sum(itogom+sumndsm) end --!!!!4,5,6
਍昀爀漀洀 搀漀挀洀愀氀漀挀 搀㄀㈀Ⰰ琀戀渀搀猀椀稀渀漀猀 最Ⰰ琀戀最爀漀瀀攀爀 最㈀ ഀഀ
where d12.datedocm  between @D1 and @D2  and pr in (3,4,6)
਍ 愀渀搀⼀⨀ 瀀爀㴀㌀ 愀渀搀⨀⼀ ⠀挀愀猀攀 眀栀攀渀 ⠀瀀爀㴀㌀⤀ 琀栀攀渀 ⠀猀甀洀渀搀猀漀漀㄀　洀⤀  攀氀猀攀 ㄀ 攀渀搀⤀㰀㸀　  愀渀搀 最⸀椀搀最爀漀瀀攀爀㴀搀㄀㈀⸀椀搀最爀漀瀀攀爀洀 愀渀搀 搀㄀㈀⸀椀搀最爀漀瀀攀爀洀㴀最㈀⸀椀搀最爀漀瀀攀爀ഀഀ
group by pr,convert(varchar(3),g.kodschetdt)+case  when(g.kodsubschetdt<10) then '0'+convert(varchar(3),g.kodsubschetdt) else convert(varchar(3),g.kodsubschetdt)end,
਍         挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀挀栀攀琀欀琀⤀⬀挀愀猀攀  眀栀攀渀⠀最⸀欀漀搀猀甀戀猀挀栀攀琀欀琀㰀㄀　⤀ 琀栀攀渀 ✀　✀⬀挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀甀戀猀挀栀攀琀欀琀⤀ 攀氀猀攀 挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀甀戀猀挀栀攀琀欀琀⤀攀渀搀Ⰰഀഀ
case when (g.tipeanal in (1,3)) then g.praprizschet end,case when (g.tipeanal=2) then g.praprizschet when (g.tipeanal=3) then g.praprizschetkt end 
਍ഀഀ
union all--7
਍ 猀攀氀攀挀琀 瀀爀Ⰰ 挀愀猀攀 眀栀攀渀 ⠀最⸀琀椀瀀攀愀渀愀氀 椀渀 ⠀㄀Ⰰ㌀⤀⤀ 琀栀攀渀 最⸀瀀爀愀瀀爀椀稀猀挀栀攀琀 攀渀搀 愀猀 椀搀猀挀栀攀琀猀甀戀猀栀攀琀搀琀洀Ⰰ挀愀猀攀 眀栀攀渀 ⠀最⸀琀椀瀀攀愀渀愀氀㴀㈀⤀ 琀栀攀渀 最⸀瀀爀愀瀀爀椀稀猀挀栀攀琀 眀栀攀渀 ⠀最⸀琀椀瀀攀愀渀愀氀㴀㌀⤀ 琀栀攀渀 最⸀瀀爀愀瀀爀椀稀猀挀栀攀琀欀琀 攀渀搀 愀猀 椀搀猀挀栀攀琀猀甀戀猀栀攀琀欀琀洀Ⰰഀഀ
 convert(varchar(3),g.kodschetdt)+case  when(g.kodsubschetdt<10) then '0'+convert(varchar(3),g.kodsubschetdt) else convert(varchar(3),g.kodsubschetdt)end as dt,
਍挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀挀栀攀琀欀琀⤀⬀挀愀猀攀  眀栀攀渀⠀最⸀欀漀搀猀甀戀猀挀栀攀琀欀琀㰀㄀　⤀ 琀栀攀渀 ✀　✀⬀挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀甀戀猀挀栀攀琀欀琀⤀ 攀氀猀攀 挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀甀戀猀挀栀攀琀欀琀⤀攀渀搀 愀猀 欀琀Ⰰഀഀ
sum(itogom)
਍ 昀爀漀洀 搀漀挀洀愀氀漀挀 搀㄀㄀Ⰰ琀戀渀搀猀椀稀渀漀猀 最Ⰰ琀戀最爀漀瀀攀爀 最㈀ ഀഀ
 where d11.datedocm  between @D1 and @D2 
਍ 愀渀搀 瀀爀㴀㜀 愀渀搀  最⸀椀搀最爀漀瀀攀爀㴀搀㄀㄀⸀椀搀最爀漀瀀攀爀洀 愀渀搀 搀㄀㄀⸀椀搀最爀漀瀀攀爀洀㴀最㈀⸀椀搀最爀漀瀀攀爀ഀഀ

਍最爀漀甀瀀 戀礀 瀀爀Ⰰ挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀挀栀攀琀搀琀⤀⬀挀愀猀攀  眀栀攀渀⠀最⸀欀漀搀猀甀戀猀挀栀攀琀搀琀㰀㄀　⤀ 琀栀攀渀 ✀　✀⬀挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀甀戀猀挀栀攀琀搀琀⤀ 攀氀猀攀 挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀甀戀猀挀栀攀琀搀琀⤀攀渀搀Ⰰഀഀ
         convert(varchar(3),g.kodschetkt)+case  when(g.kodsubschetkt<10) then '0'+convert(varchar(3),g.kodsubschetkt) else convert(varchar(3),g.kodsubschetkt)end,
਍挀愀猀攀 眀栀攀渀 ⠀最⸀琀椀瀀攀愀渀愀氀 椀渀 ⠀㄀Ⰰ㌀⤀⤀ 琀栀攀渀 最⸀瀀爀愀瀀爀椀稀猀挀栀攀琀 攀渀搀Ⰰ挀愀猀攀 眀栀攀渀 ⠀最⸀琀椀瀀攀愀渀愀氀㴀㈀⤀ 琀栀攀渀 最⸀瀀爀愀瀀爀椀稀猀挀栀攀琀 眀栀攀渀 ⠀最⸀琀椀瀀攀愀渀愀氀㴀㌀⤀ 琀栀攀渀 最⸀瀀爀愀瀀爀椀稀猀挀栀攀琀欀琀 攀渀搀 ഀഀ

਍甀渀椀漀渀 愀氀氀ⴀⴀ 㠀ഀഀ

਍猀攀氀攀挀琀 瀀爀 Ⰰ挀愀猀攀 眀栀攀渀 ⠀最⸀琀椀瀀攀愀渀愀氀 椀渀 ⠀㄀Ⰰ㌀⤀⤀ 琀栀攀渀 最⸀瀀爀愀瀀爀椀稀猀挀栀攀琀 攀渀搀 愀猀 椀搀猀挀栀攀琀猀甀戀猀栀攀琀搀琀洀Ⰰ挀愀猀攀 眀栀攀渀 ⠀最⸀琀椀瀀攀愀渀愀氀㴀㈀⤀ 琀栀攀渀 最⸀瀀爀愀瀀爀椀稀猀挀栀攀琀 眀栀攀渀 ⠀最⸀琀椀瀀攀愀渀愀氀㴀㌀⤀ 琀栀攀渀 最⸀瀀爀愀瀀爀椀稀猀挀栀攀琀欀琀 攀渀搀 愀猀 椀搀猀挀栀攀琀猀甀戀猀栀攀琀欀琀洀Ⰰഀഀ
convert(varchar(3),g.kodschetdt)+case when(g.kodsubschetdt<10) then '0'+convert(varchar(3),g.kodsubschetdt) else convert(varchar(3),g.kodsubschetdt)end as dt,
਍ 挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀挀栀攀琀欀琀⤀⬀挀愀猀攀 眀栀攀渀⠀最⸀欀漀搀猀甀戀猀挀栀攀琀欀琀㰀㄀　⤀ 琀栀攀渀 ✀　✀⬀挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀甀戀猀挀栀攀琀欀琀⤀ 攀氀猀攀 挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀甀戀猀挀栀攀琀欀琀⤀ 攀渀搀 愀猀 欀琀Ⰰഀഀ
1 as b
਍ⴀⴀ猀甀洀⠀猀攀氀攀挀琀 猀甀洀⠀挀攀渀漀洀漀琀瀀甀猀欀⨀欀漀氀昀洀⤀ 昀爀漀洀 猀琀爀椀渀最洀愀氀漀挀 眀栀攀爀攀 猀琀爀椀渀最洀愀氀漀挀⸀椀搀搀漀挀洀㴀搀㄀㄀⸀椀搀搀漀挀洀⤀ 愀猀 椀琀漀最漀洀 ഀഀ
 from docmaloc d11,tbndsiznos g,tbgroper g2 --aii pr=8
਍ 眀栀攀爀攀 搀㄀㄀⸀搀愀琀攀搀漀挀洀  戀攀琀眀攀攀渀 䀀䐀㄀ 愀渀搀 䀀䐀㈀  ഀഀ
 and pr=8 and  g.idgroper=d11.idgroperm and d11.idgroperm=g2.idgroper
਍最爀漀甀瀀 戀礀 瀀爀Ⰰ挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀挀栀攀琀搀琀⤀⬀挀愀猀攀  眀栀攀渀⠀最⸀欀漀搀猀甀戀猀挀栀攀琀搀琀㰀㄀　⤀ 琀栀攀渀 ✀　✀⬀挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀甀戀猀挀栀攀琀搀琀⤀ 攀氀猀攀 挀漀渀瘀攀爀琀⠀瘀愀爀挀栀愀爀⠀㌀⤀Ⰰ最⸀欀漀搀猀甀戀猀挀栀攀琀搀琀⤀攀渀搀Ⰰഀഀ
         convert(varchar(3),g.kodschetkt)+case  when(g.kodsubschetkt<10) then '0'+convert(varchar(3),g.kodsubschetkt) else convert(varchar(3),g.kodsubschetkt)end,
਍挀愀猀攀 眀栀攀渀 ⠀最⸀琀椀瀀攀愀渀愀氀 椀渀 ⠀㄀Ⰰ㌀⤀⤀ 琀栀攀渀 最⸀瀀爀愀瀀爀椀稀猀挀栀攀琀 攀渀搀Ⰰ挀愀猀攀 眀栀攀渀 ⠀最⸀琀椀瀀攀愀渀愀氀㴀㈀⤀ 琀栀攀渀 最⸀瀀爀愀瀀爀椀稀猀挀栀攀琀 眀栀攀渀 ⠀最⸀琀椀瀀攀愀渀愀氀㴀㌀⤀ 琀栀攀渀 最⸀瀀爀愀瀀爀椀稀猀挀栀攀琀欀琀 攀渀搀 ഀഀ
order by 1
਍䜀伀ഀഀ
SET QUOTED_IDENTIFIER OFF 
਍䜀伀ഀഀ
SET ANSI_NULLS ON 
਍䜀伀ഀഀ

਍�