Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

DECLARE @PeriodFR nvarchar(6)

DECLARE @PeriodTO nvarchar(6)


DECLARE @Project nvarchar(8)
DECLARE @OBACCT nvarchar(8)
SET @PeriodFR = '202401'
SET @PeriodTO = '202405'
SET @Project = 'P'
SET @OBACCT = '12020177'

select
OPRJ.PrjCode as 'Project Code',
OPRJ.PrjName as 'Project Name',
--Get Open Bal.
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate < cast(@PeriodFR+'01' as date)
),0) as 'Opening Bal.',
--Get Additional
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Transtype in ('18',
'19','59','60')
),0) as 'Additional',
--Get TRF. to FA
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Transtype in
('1470000049', '1470000060')
),0) as 'TRF. to FA',
--Write off to OH/Adjust
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Ref3Line = 'OH'
),0) as 'Write off to OH/Adjust',

--Period Totals
(isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Transtype in ('18',
'19','59','60')
),0) +
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Transtype in
('1470000049', '1470000060')
),0) +
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Ref3Line = 'OH'
),0))

as 'Period Total',
--Closing Bal.
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate < cast(@PeriodFR+'01' as date)
),0) -
(isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Transtype in ('18',
'19','59','60')
),0) +
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Transtype in
('1470000049', '1470000060')
),0) +
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Ref3Line = 'OH'
),0))

as 'Closing Bal.',
--RFA Budget after cap. to FA
isnull(OPRJ.U_RFABgAmt,0) as 'RFA Budget after cap. to FA',
--Budget Variance
isnull(OPRJ.U_RFABgAmt,0) -
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate < cast(@PeriodFR+'01' as date)
),0) -
(isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Transtype in ('18',
'19','59','60')
),0) +
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Transtype in
('1470000049', '1470000060')
),0) +
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Ref3Line = 'OH'
),0))as 'Budget Variance'

from OPRJ where OPRJ.PrjCode like @Project+'%'


--from OPRJ where OPRJ.PrjCode = 'P22351'

You might also like