select
doc.DOC_TYPE_ID,
bp.[name] as N'პროგრამა',
bpc.[name] as N'კომპონენტი',
bpsc.[name] as N'სუბკომპონენტი',
con.NO_OLD_STYLE as N'კონტრაქტი',
org.[name] as N'ორგანიზაცია',
ps.id as N'შესრულების ID',
convert(varchar(20),ps.reporting_period_start,102)+
'-'+convert(varchar(20),ps.reporting_period_end,102) as N'ანგარიშგების პერიოდი',
st.[name] as N'შესრულების სტატუსი',

dd.*



from
BUDGET_PROGRAM bp INNER JOIN
BUDGET_PROGRAM_COMPONENT bpc ON bp.ID=bpc.BUDGET_PROGRAM_ID INNER JOIN
BUDGET_PROGRAM_SUBCOMPONENT bpsc ON bpsc.BUDGET_PROGRAM_COMPONENT_ID=bpc.ID INNER JOIN
[CONTRACT] con ON con.BUDGET_PROGRAM_SUBCOMPONENT_ID=bpsc.ID INNER JOIN
ORGANIZATION org ON con.ORGANIZATION_ID=org.id INNER JOIN
PROVIDED_SERVICE ps ON ps.CONTRACT_ID=con.ID inner join 
dbo.STATUS st on ps.status_id=st.id inner join
DOC doc ON ps.ID=doc.PROVIDED_SERVICE_ID AND doc.DOC_TYPE_ID not in (60,73) INNER JOIN
DOC_DETAIL dd ON (dd.DOC_ID=doc.ID)
where 
doc.DOC_TYPE_ID=
and
bpc.id=505
and
ps.reporting_period_start>'2013.11.30 00:00:00.000'
and ps.reporting_period_end<'2014.07.01 00:00:00.000'


