I successfully create a temporary table of all pay dates for an employee:
Create Table #tmp (
hr_pe_id Char(9),
hr_pe_name Char(30),
pyh_ck_dt Char(8),
retire_code Char(4),
retire_title Char(20),
retire_amt Int,
hrs_code Char(4),
hrs_title Char(20),
hrs_amt Int,
hrs_wrkd_code Char(4),
hrs_wrkd_title Char(20),
hrs_wrkd_amt Int,
hrs_rate_code Char(4),
hrs_rate_title Char(20),
hrs_rate_amt Int,
gr_earn_code Char(4),
gr_earn_title Char(20),
gr_earn_amt Int
)
GO
Insert INTO #tmp(hr_pe_id, hr_pe_name, pyh_ck_dt)
select DISTINCT RTRIM(h.hr_pe_id), RTRIM(e.hr_pe_name), h.pyh_ck_dt
from pyh_hst_dtl h
left join hr_pe_mstr e on e.hr_pe_id = h.hr_pe_id
where h.hr_pe_id = '999999999' and h.pyh_ck_dt IS NOT NULL
GROUP BY h.hr_pe_id, e.hr_pe_name, h.pyh_ck_dt
hr_pe_id hr_pe_name pyh_ck_dt
999999999 ANDERSEN, JAMES 19921231
999999999 ANDERSEN, JAMES 19930115
999999999 ANDERSEN, JAMES 19930129
999999999 ANDERSEN, JAMES 19930212
999999999 ANDERSEN, JAMES 19930226
999999999 ANDERSEN, JAMES 19930315
999999999 ANDERSEN, JAMES 19930331
I now want to go to the EmployeeDeductions table, find records with the same employee ID and paycheck dates, and update the tmp table with the data. My commands are listed below but I'm confused as to how to start the process of reading sequential records in the EmployeeDeductions table and updating tmp when it needs to be updated.
set
retire_code = (Select d.DeductionCode
from EmployeeDeductions d
where d.DeductionCode = 2100 and d.hr_pe_id = hr_pe_id
and d.pyh_ck_dt = pyh_ck_dt),
retire_title = (select c.py_cdh_cd
from py_cdh_mstr c
where c.py_cdh_no = 2100),
retire_amt = (select d.Amount
from EmployeeDeductions d
where d.DeductionCode = 2100 and d.hr_pe_id = hr_pe_id
and d.pyh_ck_dt = pyh_ck_dt)
S8730 Processors (Redundncy/Mirror Img)
Aura 5.2 (Communication Manager)
Modular Messaging 5.2
Create Table #tmp (
hr_pe_id Char(9),
hr_pe_name Char(30),
pyh_ck_dt Char(8),
retire_code Char(4),
retire_title Char(20),
retire_amt Int,
hrs_code Char(4),
hrs_title Char(20),
hrs_amt Int,
hrs_wrkd_code Char(4),
hrs_wrkd_title Char(20),
hrs_wrkd_amt Int,
hrs_rate_code Char(4),
hrs_rate_title Char(20),
hrs_rate_amt Int,
gr_earn_code Char(4),
gr_earn_title Char(20),
gr_earn_amt Int
)
GO
Insert INTO #tmp(hr_pe_id, hr_pe_name, pyh_ck_dt)
select DISTINCT RTRIM(h.hr_pe_id), RTRIM(e.hr_pe_name), h.pyh_ck_dt
from pyh_hst_dtl h
left join hr_pe_mstr e on e.hr_pe_id = h.hr_pe_id
where h.hr_pe_id = '999999999' and h.pyh_ck_dt IS NOT NULL
GROUP BY h.hr_pe_id, e.hr_pe_name, h.pyh_ck_dt
hr_pe_id hr_pe_name pyh_ck_dt
999999999 ANDERSEN, JAMES 19921231
999999999 ANDERSEN, JAMES 19930115
999999999 ANDERSEN, JAMES 19930129
999999999 ANDERSEN, JAMES 19930212
999999999 ANDERSEN, JAMES 19930226
999999999 ANDERSEN, JAMES 19930315
999999999 ANDERSEN, JAMES 19930331
I now want to go to the EmployeeDeductions table, find records with the same employee ID and paycheck dates, and update the tmp table with the data. My commands are listed below but I'm confused as to how to start the process of reading sequential records in the EmployeeDeductions table and updating tmp when it needs to be updated.
set
retire_code = (Select d.DeductionCode
from EmployeeDeductions d
where d.DeductionCode = 2100 and d.hr_pe_id = hr_pe_id
and d.pyh_ck_dt = pyh_ck_dt),
retire_title = (select c.py_cdh_cd
from py_cdh_mstr c
where c.py_cdh_no = 2100),
retire_amt = (select d.Amount
from EmployeeDeductions d
where d.DeductionCode = 2100 and d.hr_pe_id = hr_pe_id
and d.pyh_ck_dt = pyh_ck_dt)
S8730 Processors (Redundncy/Mirror Img)
Aura 5.2 (Communication Manager)
Modular Messaging 5.2