Friday, February 10, 2017

F1602 Data recalss

--select right(rtrim(CBABR1),2) FY ,left(rtrim(CBABR1),2) PN,CBAID,CBLT,CBSBL,CBSBLT,cban11/100 Amt into #temp_11 from oracleF1602   where cbuser = 'CHUCHRIS' and CBCFY=@fy order by 1,2
--select right(rtrim(CBABR1),2) FY ,left(rtrim(CBABR1),2) PN,CBAID,CBLT,CBSBL,CBSBLT,cban11/100 Amt  from oracleF1602   where cbuser = 'CHUCHRIS' and CBCFY=2016 order by 1,2
--select *  from oracleF1602   where cbuser = 'CHUCHRIS' and CBCFY=2016 order by 1,2
declare  @fy int=2016

--PN 10
drop table #temp_10
select right(rtrim(CBABR1),2) FY ,left(rtrim(CBABR1),2) PN,CBAID,CBLT,CBSBL,CBSBLT,cban10/100 Amt into #temp_10 from oracleF1602   where cbuser = 'CHUCHRIS' and CBCFY=@fy order by 1,2
drop table #temp_10_2
select FY,CBAID,CBLT,CBSBL,CBSBLT,
ISNULL([01],0) Period_01, ISNULL([02],0) Period_02, ISNULL([03],0) Period_03,ISNULL([04],0) Period_04, ISNULL([05],0) Period_05, ISNULL([06],0) Period_06,
ISNULL([07],0) Period_07, ISNULL([08],0) Period_08, ISNULL([09],0) Period_09,ISNULL([10],0) Period_10, ISNULL([11],0) Period_11, ISNULL([12],0) Period_12 into #temp_10_2
from
(
  select FY,PN,CBAID,CBLT,CBSBL,CBSBLT,amt
  from #temp_10
) src
pivot
(
  sum(Amt)
  for pn in ([01], [02], [03],[04], [05], [06],[07], [08], [09],[10], [11], [12])
) piv
order by 2;
select '10' ForPN, * from  #temp_10_2



--PN 11
drop table #temp_11
select right(rtrim(CBABR1),2) FY ,left(rtrim(CBABR1),2) PN,CBAID,CBLT,CBSBL,CBSBLT,cban11/100 Amt into #temp_11 from oracleF1602   where cbuser = 'CHUCHRIS' and CBCFY=@fy order by 1,2
drop table #temp_11_2
select FY,CBAID,CBLT,CBSBL,CBSBLT,
ISNULL([01],0) Period_01, ISNULL([02],0) Period_02, ISNULL([03],0) Period_03,ISNULL([04],0) Period_04, ISNULL([05],0) Period_05, ISNULL([06],0) Period_06,
ISNULL([07],0) Period_07, ISNULL([08],0) Period_08, ISNULL([09],0) Period_09,ISNULL([10],0) Period_10, ISNULL([11],0) Period_11, ISNULL([12],0) Period_12 into #temp_11_2
from
(
  select FY,PN,CBAID,CBLT,CBSBL,CBSBLT,amt
  from #temp_11
) src
pivot
(
  sum(Amt)
  for pn in ([01], [02], [03],[04], [05], [06],[07], [08], [09],[10], [11], [12])
) piv
order by 2;
select '11' ForPN, * from  #temp_11_2



--for 12
drop table #temp111
select right(rtrim(CBABR1),2) FY ,left(rtrim(CBABR1),2) PN,CBAID,CBLT,CBSBL,CBSBLT,cban12/100 Amt into #temp111 from oracleF1602   where cbuser = 'CHUCHRIS' and CBCFY=@fy order by 1,2

drop table #temp2
select FY,CBAID,CBLT,CBSBL,CBSBLT,
ISNULL([01],0) Period_01, ISNULL([02],0) Period_02, ISNULL([03],0) Period_03,ISNULL([04],0) Period_04, ISNULL([05],0) Period_05, ISNULL([06],0) Period_06,
ISNULL([07],0) Period_07, ISNULL([08],0) Period_08, ISNULL([09],0) Period_09,ISNULL([10],0) Period_10, ISNULL([11],0) Period_11, ISNULL([12],0) Period_12 into #temp2
from
(
  select FY,PN,CBAID,CBLT,CBSBL,CBSBLT,amt
  from #temp111
) src
pivot
(
  sum(Amt)
  for pn in ([01], [02], [03],[04], [05], [06],[07], [08], [09],[10], [11], [12])
) piv
order by 2;

select '12' ForPN, * from #temp2



No comments: