0% found this document useful (0 votes)
69 views7 pages

Payslip Queries

The document contains 4 SQL queries that are selecting data from various HR, payroll and financial tables. The queries are joining these tables to retrieve employee, assignment, pay period and payment information such as employee ID, name, payroll period, payment amounts. The where clauses filter for specific payment action types, periods and other attributes. The results are being grouped, summed and ordered.

Uploaded by

mohamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views7 pages

Payslip Queries

The document contains 4 SQL queries that are selecting data from various HR, payroll and financial tables. The queries are joining these tables to retrieve employee, assignment, pay period and payment information such as employee ID, name, payroll period, payment amounts. The where clauses filter for specific payment action types, periods and other attributes. The results are being grouped, summed and ordered.

Uploaded by

mohamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

Query1

=====================================================================
SELECT ppf.employee_number, ppf.full_name, ppf.national_identifier,
ppf.internal_location nssf_no, ppf.MAILSTOP nhif_no,
ppf.OFFICE_NUMBER pin_no, paf.assignment_id,
location_code location_code, ftt.territory_short_name country,
hou.NAME org, pap.NAME POSITION, pg.NAME grade,
ftt.territory_short_name, ptp.period_name, pay.payroll_name,
TO_CHAR (ptp.start_date, 'Month-YYYY') pay_month, ppf.person_id
FROM per_assignments_f paf,
per_people_f ppf,
hr_locations hl,
pay_payrolls_f pay,
per_time_periods ptp,
pay_payroll_actions ppa,
pay_element_types_f petf,
pay_element_classifications pec,
pay_input_values_f piv,
per_grades pg,
hr_organization_units hou,
per_positions pap,
fnd_territories_tl ftt
WHERE paf.person_id = ppf.person_id
AND paf.location_id = hl.location_id
AND paf.payroll_id = pay.payroll_id
AND paf.payroll_id = ptp.payroll_id
AND paf.payroll_id = ppa.payroll_id
AND ptp.time_period_id = ppa.time_period_id
AND petf.classification_id = pec.classification_id
AND piv.element_type_id = petf.element_type_id
AND piv.NAME = 'Pay Value'
AND ppa.action_type IN ('Q', 'R')
AND pec.classification_name LIKE '%Earnings%'
AND TRUNC (ppa.effective_date) BETWEEN paf.effective_start_date
AND paf.effective_end_date
AND TRUNC (ppa.effective_date) BETWEEN ppf.effective_start_date
AND ppf.effective_end_date
AND TRUNC (ppa.effective_date) BETWEEN pay.effective_start_date
AND pay.effective_end_date
AND TRUNC (ppa.effective_date) BETWEEN ptp.start_date AND ptp.end_date
AND TRUNC (ppa.effective_date) BETWEEN petf.effective_start_date
AND petf.effective_end_date
AND ptp.time_period_id IN (
SELECT time_period_id
FROM per_time_periods
WHERE payroll_id = paf.payroll_id
AND time_period_id = :p_time_period_id)
AND paf.person_id = nvl(:p_emp,paf.person_id)
AND paf.grade_id = pg.grade_id(+)
AND PAY.PAYROLL_ID = NVL(:P_PAYROLL,PAY.PAYROLL_ID)
AND paf.organization_id = hou.organization_id
AND paf.position_id = pap.position_id(+)
AND hl.country = ftt.territory_code(+)
AND ftt.LANGUAGE = 'US'
GROUP BY ppf.employee_number,
ppf.full_name,
ppf.national_identifier,
ppf.internal_location,
ppf.MAILSTOP,
ppf.OFFICE_NUMBER,
paf.assignment_id,
hl.location_code,
hou.NAME,
pap.NAME,
pg.NAME,
ftt.territory_short_name,
ptp.period_name,
pay.payroll_name,
TO_CHAR (ptp.start_date, 'Month-YYYY'),
ppf.person_id
ORDER BY PPF.EMPLOYEE_NUMBER;

Query2
======================================================================
select assignment_id,person_id,element_name,result_value,assignment_action_id from
(select paf.assignment_id
,paf.person_id
,petf.reporting_name element_name
,sum(prrv.result_value) result_value
,paa.assignment_action_id
from per_assignments_f paf
,pay_payrolls_f pay
,per_time_periods ptp
,pay_payroll_actions ppa
,pay_assignment_actions paa
,pay_run_results prr
,pay_element_types_f petf
,pay_element_classifications pec
,pay_run_result_values prrv
,pay_input_values_f piv
where 1=1
and paf.payroll_id = pay.payroll_id
and paf.payroll_id = ptp.payroll_id
and paf.payroll_id = ppa.payroll_id
and ptp.time_period_id = ppa.time_period_id
and paa.payroll_action_id = ppa.payroll_action_id
and paf.assignment_id = paa.assignment_id
and prr.assignment_action_id = paa.assignment_action_id
and petf.element_type_id = prr.element_type_id
and petf.classification_id = pec.classification_id
and prr.run_result_id = prrv.run_result_id
and prrv.input_value_id = piv.input_value_id
and piv.element_type_id = petf.element_type_id
and piv.name = 'Pay Value'
and ppa.action_type IN ('Q', 'R')
and pec.classification_name like '%Earnings%'
and trunc(ppa.effective_date) between paf.effective_start_date and
paf.effective_end_date
and trunc(ppa.effective_date) between pay.effective_start_date and
pay.effective_end_date
and trunc(ppa.effective_date) between ptp.start_date and ptp.end_date
and trunc(ppa.effective_date) between petf.effective_start_date and
petf.effective_end_date
--and paf.person_id=62
and ptp.TIME_PERIOD_ID IN (select time_period_id
from per_time_periods
where payroll_id = paf.payroll_id
and time_PERIOD_id=:P_TIME_PERIOD_ID )
AND PAY.PAYROLL_ID = NVL(:P_PAYROLL,PAY.PAYROLL_ID)
group by paf.assignment_id
,paf.person_id
,petf.reporting_name
,paa.assignment_action_id)
where result_value != '0'
order by element_name;

Query3
=======================================================================
select paf.assignment_id
,paf.person_id
,petf.reporting_name element_name
,sum(prrv.result_value) result_value
,paa.assignment_action_id
from per_assignments_f paf
,pay_payrolls_f pay
,per_time_periods ptp
,pay_payroll_actions ppa
,pay_assignment_actions paa
,pay_run_results prr
,pay_element_types_f petf
,pay_element_classifications pec
,pay_run_result_values prrv
,pay_input_values_f piv
where 1=1
and paf.payroll_id = pay.payroll_id
and paf.payroll_id = ptp.payroll_id
and paf.payroll_id = ppa.payroll_id
and ptp.time_period_id = ppa.time_period_id
and paa.payroll_action_id = ppa.payroll_action_id
and paf.assignment_id = paa.assignment_id
and prr.assignment_action_id = paa.assignment_action_id
and petf.element_type_id = prr.element_type_id
and petf.classification_id = pec.classification_id
and prr.run_result_id = prrv.run_result_id
and prrv.input_value_id = piv.input_value_id
and piv.element_type_id = petf.element_type_id
and piv.name = 'Pay Value'
and ppa.action_type IN ('Q', 'R')
and pec.classification_name like '%Deductions%'
and prrv.result_value !='0'
and trunc(ppa.effective_date) between paf.effective_start_date and
paf.effective_end_date
and trunc(ppa.effective_date) between pay.effective_start_date and
pay.effective_end_date
and trunc(ppa.effective_date) between ptp.start_date and ptp.end_date
and trunc(ppa.effective_date) between petf.effective_start_date and
petf.effective_end_date
--and paf.person_id=62
and ptp.TIME_PERIOD_ID IN (select time_period_id
from per_time_periods
where payroll_id = paf.payroll_id
and time_period_id=:P_TIME_PERIOD_ID )
AND PAY.PAYROLL_ID = NVL(:P_PAYROLL,PAY.PAYROLL_ID)
group by paf.assignment_id
,petf.reporting_name
,paa.assignment_action_id
,petf.ATTRIBUTE1
,paf.person_id
order by petf.reporting_name

Query4
=======================================================================
select paf.assignment_id
,paf.person_id
,petf.reporting_name element_name
--,sum(prrv.result_value) result_value
,prrv.result_value
,paa.assignment_action_id
from per_assignments_f paf
,pay_payrolls_f pay
,per_time_periods ptp
,pay_payroll_actions ppa
,pay_assignment_actions paa
,pay_run_results prr
,pay_element_types_f petf
,pay_element_classifications pec
,pay_run_result_values prrv
,pay_input_values_f piv
where 1=1
and paf.payroll_id = pay.payroll_id
and paf.payroll_id = ptp.payroll_id
and paf.payroll_id = ppa.payroll_id
and ptp.time_period_id = ppa.time_period_id
and paa.payroll_action_id = ppa.payroll_action_id
and paf.assignment_id = paa.assignment_id
and prr.assignment_action_id = paa.assignment_action_id
and petf.element_type_id = prr.element_type_id
and petf.classification_id = pec.classification_id
and prr.run_result_id = prrv.run_result_id
and prrv.input_value_id = piv.input_value_id
and piv.element_type_id = petf.element_type_id
and piv.name = 'Pay Value'
and ppa.action_type IN ('Q', 'R')
-- and pec.classification_name like '%Information%'
and petf.element_name in ('CA Insurance Relief',
'CA Central Organization of Trade Unions Balance',
'CA Comm Sacco Special Savings Scheme Balance',
'CA Communications Sacco Shares Balance',
'CA Communications Sacco Investment Shares Balance',
'CA Comm Workers Union of Kenya Balance',
'CA NSSF Balance',
'CA Pension Balance',
'CA Car Loan Outstanding',
'CA Car Insurance Advance Outstanding',
'CA Communications Sacco Cooperative Development Loan Outstanding',
'CA Communications Sacco Cooperative Emergency Loan I Outstanding',
'CA Communications Sacco Cooperative Emergency Loan II Outstanding',
'CA Car Overhaul Advance Outstanding',
'CA Communications Sacco Cooperative Instant Loan Outstanding',
'CA Communications Sacco Cooperative School Fees Loan Outstanding',
'CA Communications Sacco Shamba Loan Outstanding',
'CA Fire and Mortgage Outstanding',
'CA Furniture Loan Outstanding',
'CA HELB Outstanding',
'CA Kenya Police Sacco Loan Outstanding',
'CA Property Loan Outstanding',
'CA Salary Advance Outstanding',
'CA Construction Loan Outstanding',
'CA House Purchase Loan Outstanding',
'CA House Refinancing Outstanding',
'CA Outpatient Recovery Outstanding',
'CA Personal Relief',
'CA Gratuity Accrual',
'CA Gratuity Balance',
'CA Pension Recovery Outstanding',
'CA Imprest Recovery Outstanding',
'CA Temp Gratuity Accrual')
and prrv.result_value !='0'
--and petf.ATTRIBUTE2='Yes'
and trunc(ppa.effective_date) between paf.effective_start_date and
paf.effective_end_date
and trunc(ppa.effective_date) between pay.effective_start_date and
pay.effective_end_date
and trunc(ppa.effective_date) between ptp.start_date and ptp.end_date
and trunc(ppa.effective_date) between petf.effective_start_date and
petf.effective_end_date
-- and paf.person_id=119
and ptp.TIME_PERIOD_ID IN (select time_period_id
from per_time_periods
where payroll_id = paf.payroll_id
and time_PERIOD_id=:P_TIME_PERIOD_ID )
AND PAY.PAYROLL_ID = NVL(:P_PAYROLL,PAY.PAYROLL_ID)

group by paf.assignment_id
,petf.reporting_name
,paa.assignment_action_id
,prrv.result_value
,paf.person_id
order by petf.reporting_name

Query5
=======================================================================
select paf.assignment_id
,paf.person_id
,petf.reporting_name element_name
,sum(prrv.result_value) result_value
,paa.assignment_action_id
from per_assignments_f paf
,pay_payrolls_f pay
,per_time_periods ptp
,pay_payroll_actions ppa
,pay_assignment_actions paa
,pay_run_results prr
,pay_element_types_f petf
,pay_element_classifications pec
,pay_run_result_values prrv
,pay_input_values_f piv
where 1=1
and paf.payroll_id = pay.payroll_id
and paf.payroll_id = ptp.payroll_id
and paf.payroll_id = ppa.payroll_id
and ptp.time_period_id = ppa.time_period_id
and paa.payroll_action_id = ppa.payroll_action_id
and paf.assignment_id = paa.assignment_id
and prr.assignment_action_id = paa.assignment_action_id
and petf.element_type_id = prr.element_type_id
and petf.classification_id = pec.classification_id
and prr.run_result_id = prrv.run_result_id
and prrv.input_value_id = piv.input_value_id
and piv.element_type_id = petf.element_type_id
and piv.name = 'Pay Value'
and ppa.action_type IN ('Q', 'R')
and pec.classification_name like '%Taxable Benefits%'
and prrv.result_value !='0'
and trunc(ppa.effective_date) between paf.effective_start_date and
paf.effective_end_date
and trunc(ppa.effective_date) between pay.effective_start_date and
pay.effective_end_date
and trunc(ppa.effective_date) between ptp.start_date and ptp.end_date
and trunc(ppa.effective_date) between petf.effective_start_date and
petf.effective_end_date
-- and paf.person_id=62
and ptp.TIME_PERIOD_ID IN (select time_period_id
from per_time_periods
where payroll_id = paf.payroll_id
and time_period_id=:P_TIME_PERIOD_ID )
AND PAY.PAYROLL_ID = NVL(:P_PAYROLL,PAY.PAYROLL_ID)
group by paf.assignment_id
,petf.reporting_name
,paa.assignment_action_id
,paf.person_id

Query6
=======================================================================
SELECT PAPF.PERSON_ID
,paaf.ASSIGNMENT_ID
,PEA.SEGMENT1 bank_code
,PEA.SEGMENT2 bank_name
,PEA.SEGMENT3 branch_code
,PEA.SEGMENT4 branch_name
,PEA.SEGMENT5 account_number
,TO_CHAR(PTP.PAY_ADVICE_DATE,'MONTH-YYYY') PAY_MONTH
FROM PER_ALL_PEOPLE_F PAPF
,PER_ALL_ASSIGNMENTS_F PAAF
,HR_LOCATIONS HR
,PER_GRADES PG
,PER_JOBS PJ
,PER_PERSON_TYPES PPT
,PAY_PERSONAL_PAYMENT_METHODS_F PPPM
,PAY_EXTERNAL_ACCOUNTS PEA
,PER_TIME_PERIODS PTP
-- ,FND_USER FU
WHERE PAPF.PERSON_ID=PAAF.PERSON_ID(+)
AND PTP.PAY_ADVICE_DATE BETWEEN PAPF.EFFECTIVE_START_DATE AND
PAPF.EFFECTIVE_END_DATE
AND PTP.PAY_ADVICE_DATE BETWEEN PAAF.EFFECTIVE_START_DATE AND
PAAF.EFFECTIVE_END_DATE
AND PTP.PAY_ADVICE_DATE BETWEEN PPPM.EFFECTIVE_START_DATE AND
PPPM.EFFECTIVE_END_DATE
AND PAAF.LOCATION_ID=HR.LOCATION_ID
AND PAAF.GRADE_ID=PG.GRADE_ID(+)
AND PAAF.JOB_ID=PJ.JOB_ID(+)
AND PAPF.PERSON_TYPE_ID=PPT.PERSON_TYPE_ID
AND PAAF.ASSIGNMENT_ID=PPPM.ASSIGNMENT_ID(+)
AND PPPM.EXTERNAL_ACCOUNT_ID=PEA.EXTERNAL_ACCOUNT_ID(+)
AND PAAF.PAYROLL_ID=PTP.PAYROLL_ID
and pppm.PRIORITY=1
and ptp.TIME_PERIOD_ID IN (select time_period_id
from per_time_periods
where payroll_id = PAAF.payroll_id
and time_period_id=:P_TIME_PERIOD_ID )
and paaf.PAYROLL_ID =
nvl(:P_PAYROLL,paaf.PAYROLL_ID)
and PAPF.person_id = nvl(:p_emp,papf.person_id)

You might also like