Files
hallasanup/쿼리/Template/인건비반영제거하기.sql
2026-06-22 20:28:21 +09:00

158 lines
3.9 KiB
Transact-SQL

-- ==========================================
-- 작업일자: YYYY-MM-DD [쿼리 작성 및 실행 날짜를 기록합니다.]
-- 작 성 자: [실행자 이름을 기록합니다.]
-- 작업목적: [인건비 일괄 입력된 자료가 중복되거나 잘못 입력된 경우 삭제하고 실행예산 투입실적금액을 변경할 경우 사용합니다.]
-- 요청자/티켓번호: [요청 부서 / 요청자 또는 이슈 번호를 기록합니다.]
-- ==========================================
declare @yy char(4), @mm char(2)
-- [0] 변경할 데이터 설정
select @yy = '2022', @mm = '10'
-- [1] 인건비, 직접경비, 경상비 데이터 검증 (조회) : 중복 여부 미리 확인 권장
select * from GA.dbo.ga_pay where yy = @yy and mm = @mm
select * from HPOIMS.dbo.ys_direct_cost where jcost_desc like @yy + ''+ @mm + '월%(AUTO)'
select * from HPOIMS.dbo.ks_indirect_cost where jcost_desc like @yy + ''+ @mm + '월%(AUTO)'
-- [2] 인건비/직접경비/경상비 일괄입력된 데이터 삭제(수정/삭제 시 주석 처리 후 공유 권장)
/*
delete from GA.dbo.ga_pay where yy = @yy and mm = @mm
delete from HPOIMS.dbo.ys_direct_cost where jcost_desc like @yy + '년 '+ @mm + '월%(AUTO)'
delete from HPOIMS.dbo.ks_indirect_cost where jcost_desc like @yy + '년 '+ @mm + '월%(AUTO)'
*/
-- [3] 인건비/직접경비/경상비 삭제에 따른 실행예산 투입실적금액 변경(수정/삭제 시 주석 처리 후 공유 권장)
/*
update
HPOIMS.dbo.ys_pbudget
set
x_amt = (b.soyo_amt+b.input_amt)
from
HPOIMS.dbo.ys_pbudget a
join
(
select
*
from
(
select
a.pjt_no, a.main, a.sub, a.bud_seq
, sum(a.bud_amt) bud_amt
, sum(a.bud_x_amt) bud_x_amt
, sum(a.bud_e_amt) bud_e_amt
, sum(a.soyo_amt) soyo_amt
, sum(a.input_amt ) input_amt
from
(
SELECT
pjt_no = a.pjt_no
, main = a.main
, sub = a.sub
, bud_seq = a.bud_seq
, closing_yn = ISNULL(a.closing_yn,'N')
, bud_amt = ISNULL(a.amt,0)
, bud_x_amt = ISNULL(a.x_amt,0)
, bud_e_amt = ISNULL(a.e_amt,0)
, soyo_amt = 0
, input_amt = 0
FROM
HPOIMS.dbo.ys_pbudget a
UNION ALL
SELECT
pjt_no = a.pjt_no
, main = a.main
, sub = a.sub
, bud_seq = a.bud_seq
, closing_yn = ''
, bud_amt = 0
, bud_x_amt = 0
, bud_e_amt = 0
, soyo_amt = SUM(ISNULL(a.w_amt,0))
, input_amt = 0
FROM
HPOIMS.dbo.gm_por_detail a
GROUP BY
a.pjt_no, a.main, a.sub, a.bud_seq
UNION ALL
SELECT
pjt_no = a.pjt_no
, main = a.main
, sub = a.sub
, bud_seq = a.bud_seq
, closing_yn = ''
, bud_amt = 0
, bud_x_amt = 0
, bud_e_amt = 0
, soyo_amt = 0
, input_amt = SUM(ISNULL(a.amt,0))
FROM
HPOIMS.dbo.ys_direct_cost a
GROUP BY
a.pjt_no, a.main, a.sub, a.bud_seq
) a
GROUP BY
a.pjt_no, a.main, a.sub, a.bud_seq
) a
where
a.bud_x_amt <> (a.soyo_amt+a.input_amt)
) b
on
a.pjt_no = b.pjt_no
and a.main = b.main
and a.sub = b.sub
and a.bud_seq = b.bud_seq
and a.pjt_no like '%'
and a.main <> 'AB00'
and a.curr = 'WON'
and ROUND(isnull(a.x_amt,0)*a.base_rate,0) <> (b.soyo_amt+b.input_amt)
update
HPOIMS.dbo.ks_budget
set
budget_use = b.amt
from
HPOIMS.dbo.ks_budget a
join
(
select
a.*
from
(
select
a.dept_cd, a.year, a.month, a.main_cd, a.sub_cd, isnull(a.budget_use,0) budget_use , isnull(b.amt,0) amt
from
HPOIMS.dbo.ks_budget a
left outer join
(
select
dept_cd, year, month, main_cd, sub_cd, sum(amt) amt
from
HPOIMS.dbo.ks_indirect_cost
where
ctr_yn = 'Y'
group by
dept_cd, year, month, main_cd, sub_cd
) b
on
a.dept_cd = b.dept_cd
and a.year = b.year
and a.month = b.month
and a.main_cd = b.main_cd
and a.sub_cd = b.sub_cd
) a
where
a.budget_use <> a.amt
) b
on
a.dept_cd = b.dept_cd
and a.year = b.year
and a.month = b.month
and a.main_cd = b.main_cd
and a.sub_cd = b.sub_cd
and a.year >= '2019'
*/