Você está na página 1de 127

INTRODUCTION TO

PEOPLESOFT
QUERY

1
Revised: August 2008

OVERVIEW
PeopleSoft Query
Basic ad hoc reporting tool
Allows you to write ad hoc queries and also run queries
shared by others
Allows data to be extracted to Excel

BASIC QUERY
Six steps to creating a basic query
1. Select the data record(s)
2. Select the field(s)
3. Set the query criteria
4. Edit the field properties (optional)
5. Save the query (optional)
6. Run the query

SAVED QUERY
You can access and run queries that you or others have
saved in the past
Public Queries are queries that you (or others) have saved which are
accessible by anyone
Private Queries are queries that you have saved which are only accessible by
you

When using a Public Query:


If you did not create the query: always save the query under a new name
before making any changes
OK to Run a Public Query as is without saving it under another name

NAVIGATING TO QUERY:

Reporting Tools > Query > Query Manager

Using a Saved Query

Follow along with me on this exercise


Navigate to:
Reporting Tools > Query > Query Manager
Enter EM in the Begins with search box

Click on Search button


6

Note:
The list of query names & descriptions
Ownership (Public or Private)
Edit, Run to HTML, and Excel hyperlinks

You can open an existing query by clicking on the Edit hyperlink for the query you want to
run
Using the Action drop down box you can delete, move to folder, rename or copy a query to
someone else
Do NOT delete or rename a query that was created by someone else
Click on EMP_LIST_SEN_BRTH_JMS
8

This takes us to the Fields tab of the query


Well take a closer look at this later

Click the Run Tab

Query Results:

10

Wow!

You can now format your report as you


normally would with any other Excel
spreadsheet, save the report or e-mail it
to someone.

Close the window

11

Alternate Execution Method

Click the HTML hyperlink for the query you want to run

12

Query Results

Note the report heading


13

Creating a New Query

Follow along with me on this exercise

Navigate to:
- Reporting Tools > Query > Query Manager
- Click on Create New Query

14

Record Selection

The first step is to select a data record


Note the search options:
Search By (defaults to Record Name)
Use Drop down box to see other options

Enter Personal in the search box to find the Personal Data record

15

NOTE:
Record name description
Add Record hyperlink to select the record for this query
Show Fields hyperlink to view the fields in the record
Find the PERSONAL_DATA record & click Add Record
16

Note:
Folder icon
Alias Record
Hierarchy Join
Minus Button
Fields:
Check box(es)
Key Symbol
Field names
Criteria icon
Join Record Names

17

Select the Fields

Click on the checkboxes for the following fields:


EMPLID
NAME
SEX
Birthdate

Click on the Fields tab

18

NOTE the following headings:


Col
Record.Fieldname
Format
Ord
XLAT

Agg
Heading Text
Add Criteria
Edit
Delete

19

Edit Field Properties

Locate the SEX field

Select Edit

20

Your edit choices:


Heading
No Heading
Text
RFT Short
RFT Long
Heading Text
Unique Field Name

Aggregate values
Translate Value
None
Short
Long

21

Edit the data as follows:


Heading: Text
Heading Text: Gender
Aggregate: None
Translate Value: Short
Click OK

22

Click on Reorder/Sort
Move Birthdate to Col 3
In the New Order By column: Make Sex sort order 1
Click OK
23

Note the following changes:


The Birthdate field has moved above the Sex field
The sex field is now designated as the primary sort
The short translate value will be displayed rather than a code
Column heading will show as Gender

Edit a few more field properties for practice


Edit field EMPLID
Heading Text: Employee ID
Order By: 1
24

Select the View SQL tab

The query tool automatically generates SQL (Structured Query Language) code

SQL will look familiar to those of you who wrote queries in the past using QMF and is useful
for advanced users in troubleshooting problems with a query.

25

Saving Queries

Once you have created a query,


you may want to save it prior to
running it.

Click SAVE (naming standards


follow)

Enter:
Query Name
Description
Owner
Private
Public

26

Naming Standards

Spaces & special characters are NOT allowed

All query names should begin with OX followed by:

Department abbreviation (e.g. BN for Benefits) see PS Query Help Home


Page

Descriptive name

Initials of the person who created the query


Example:
OX_Department Abbr_Descriptive Name_Initials
OX_BN_Employee_Listing_KP

27

Enter:
Query Name: OX_GBLCO_EE_LIST_INITIALS
Description: General Info About Employees
Owner: Public
Click OK
Then click the Properties link (at bottom)
28

The Properties page allows you to maintain


descriptive information related to the query:
Query Name, Description and Owner
defaulted from the Save Page
Query Type defaults to User
Distinct checkbox eliminates duplicate rows
(sporadic - current problem in Oxy PS environment)

Query Definition allows further


documentation about the query
Status Box displays the history of the last
save of the query

Click OK & then Run to execute the query

29

Examine your data


Note the Download to Excel option
Close this window by clicking the X in the upper right corner

30

Saving a query as a favorite

After you create your query:


Click the Return to Search button

Enter the query name in the search box:

31

Saving your query as a favorite

Check the Select box


Click on the Action drop down arrow
Select Add to Favorites
Click GO

32

Key Points

There are six steps to creating a query:


Select the record(s) i.e. Data Tables
Select the data field(s)
Set the query criteria
Edit the field properties (optional)
Save the query (optional)
Run the query

For translate fields, the long or short descriptions can be displayed rather than the code

Queries can be saved as public or private

The SQL statement generated by a query can be viewed by selecting the View SQL tab
(for advanced query users)

33

Individual Activity #1
You have been asked to create a query that displays the hire and termination dates of all
employees and eliminate duplicates (see page 29).

Record

EMPLOYMENT

Fields/Headings

EMPLID

Employee ID

HIRE_DT

Hire Date

TERMINATION_DT

Termination Date

LAST_DATE_WORKED

Last Date Worked

SUPERVISOR_ID

Supervisor ID

Order by

TERMINATION_DT

descending

Query Name

HIRE_TERM_QRY

34

Did you remember to:


Change field headings
Order by termination date in decending order

Click on the New Query hyperlink

35

Individual Activity #2
You have been asked to produce an updated list of employees emergency contacts.

Record

EMERGENCY_CNTCT

Fields/Headings

EMPLID

Employee ID

CONTACT_NAME

Contact Name

RELATIONSHIP

Relationship (short translate


description)

PRIMARY_CONTACT

Primary Contact

PHONE

Phone

Order by

EMPLID

CONTACT_NAME
Query Name

EMER_CNTCTS
36

Did you remember to:


Change headings?
Use short translate value for Relationship?
Order by EmplID and Contact Name?

Click on the New Query hyperlink


37

Selection Criteria

Next, we will add criteria rows to a query to return specific rows of data

Compare fields to find data matching a specific selection criteria

38

Selection Criteria
Create a basic query to capture employee data and save the query without
running it.

Record

PERSONAL_DATA

Fields

NAME
EMPLID
MAR_STATUS

Order by

NAME

Query Name/Description

CRITERIA

(short description)

Criteria for Employees

39

Did you remember to make the following field edits?


Change Name to the first field and sort by name?
Use the Short Name for the Mar_Status translation type?
Name the query and give it a description?

When youre ready, click the Criteria tab and then the Add Criteria button.

40

Choose Expression 1 Type:


Used to specify what you are comparing
Field
Expression (i.e calculation)
NOTE:
Your selection of Expression 1 Type
changes the display for Expression 1 on the
right

Expression 1:
Select the field (or Expression) you want
to compare
Field
Expression
Next well consider Condition Type

41

Condition Types
Between

Not between

Equal to

Not equal to

Greater than

Not greater than

In list

Not in list

In tree

Not in tree

Is null

Is not null

Less than

Not less than

Like

Not like

42

Note the different Expression 2 Types:


Field
Expression
Constant
Prompt
Subquery
Click the Cancel button
Click the Query tab

43

Find the field: Sex

Click the Add Criteria icon


(funnel)

44

Select Condition Type: equal to


Expression type: Constant
Expression 2: F
Click OK

45

You can apply criteria to fields that are not included in the query output

You need to know how the data is stored in the database to ensure accurate results
when the query is run

Click Save then Run to view the output

46

RESULTS

47

In addition to your current criteria, we now want to narrow the selection to retrieve only
those employees who have the capital letter D in their first name, middle initial or last
name.

From the Criteria tab, click the Add Criteria button

48

Select Expression 1 Type: Field

Expression 1: Click on the Search


icon

Select Name field from the list

Condition Type: like

Expression 2 Type: Constant

Expression 2: %D%

The Like operator is case sensitive and


uses wildcard characters to search for
data

Wildcard characters are:


% Any string of zero or more
characters
__ (underscore) Any single character

Click OK

49

Click Save
Click Run
NOTE the Logical drop down list (And/Or) for your criteria

50

RESULTS
You now have a female employees who have a capital D in their name

51

Individual Activity #3
Produce a list of all employees whose Business Title contains the word Manager. Also,
only show those who were hired after 1989.

Record

EMPLOYMENT

Fields

EMPLID

BUSINESS_TITLE
HIRE_DT
Order by

HIRE_DT

(descending)

Query Name/ Description

Business_Title

Manager Business Title Query

52

Results:

NOTE: Some fields are case sensitive which will impact your results
53

Criteria page

54

Effective Dates

Effective dated records are those records that contain the field EFFDT.

The effective date provides a history of changes over time

There are three categories of effective dates:

History

Rows of data where the Effective Date is less than the Effective
Date of the current row.

Current

The row of data with the highest effective date/sequence number


less than or equal to todays system date.

Future

Rows of data where the Effective Date is greater than todays


system date.

55

Effective Dates

Effective Dates are used in a query as criteria to select a specific population.

When you start a new query and select an effective-dated record/data table, a dialog box
will display informing you that an effective-date criteria row has been automatically
created.

56

Effective Dates

Click the New Query link

Record: JOBCODE_TBL

Click Add Record

Click OK in dialog box

Select the Criteria tab

57

Click the Edit button

58

Four effective dated comparisons:


Effective Date <
Effective Date <=
Effective Date >
Effective Date >=

Do Not Use:
First Effective Date
Last Effective Date

59

Individual Activity #4

Create a query that lists the last current job actions as of the current date for your employees.
Record

JOB

Fields/Headings

EMPLID

ID

DEPTID (column 2)

Dept ID

JOBCODE

Job Code

ACTION (short description)

Action

ACTION_REASON

Reason

EFFDT

Effective Date

LOCATION

Location

ANNUAL_RT

Annual Rate

Order by

EMPLID

Criteria

Annual salary of $50,000 or more (enter 50000)


Compensation Frequency of monthly (Enter M)

Query Name

OX_BN_CUR_ACTION_XX
60

Fields tab

61

Criteria tab

62

Results

63

Using Aggregate Functions

Five aggregate functions are available:


Average
Count
Max
Min
Sum

64

Sample Aggregate Query

Build a very simple query to list Employee IDs for employees in the
PERSONAL_DATA record (or data table)
Record: PERSONAL_DATA
Fields:
EMPLID
Query Name: EMPLNUM

Save

Run to see how many rows are returned

65

66

Now add the aggregate function to count the number of employees.


Click Fields tab
Click Edit button
Aggregate: Count
Click OK
Click Save
Click Run

67

Results

NOTE: Only one row is returned with a count of the number of Employee IDs.

68

Advanced Topics
Multiple Table Queries
Prompted Queries
Writing Expressions

69

Multiple Table Queries

PeopleSoft Query Manager allows you to join data from more than one
record/Data Table

You can join multiple records using the web-based Query Manager

70

Tables and Views

Records listed in the Record Search may represent either a Table or a View.
A Table physically stores specific data.
A View is a compilation of data that is usually retrieved from multiple tables. This can
be considered as pre-joined tables.
Some Views may already have criteria associated with them.

71

Joins

A join allows you to retrieve data from two or more records/Data Tables -or- specify
criteria from more than one record/table

Whenever you perform a join, the records are linked based on common fields.

In Query, pre-defined joins can be generated as either a Hierarchical join or a Related


Record join.
You do not have to add any criteria for pre-defined joins in order to link the records.

72

Types of Joins

Record
Hierarch

Related
Record

A Hierarchical join uses records that are parents or children of each other.
The hierarchical relationship is defined by the Parent Record in the
Application Designer.
Example: Joining employee Personal data with Dependent/Beneficiary data.

Related Record joins use records from non-hierarchical records/tables that


are related by a common field.
Example: Description tables for common codes are related records. This
relationship is determined by the Prompt Table edit defined for a field in the
Application Designer.

73

Join Example
Create the following new Query:
Record

Person_Name

Fields

Emplid
Name

74

FIELDS Tab

Return to Records Tab


Type in Job & Select the Join Record link next to the Job table
75

Click on the A=Person_Name link

76

The Emplid (Key in both records) fields are automatically linked together to join
the Person_Name record with the Job record
Click on the Add Criteria because this is the join you want.

77

The job record has become part of the query and is joined to the Person_Name
record.

NOTE: The Alias ID for the Person_Name data table is A and the Alias ID for the
Job data table is B.

78

Select the following Fields from the JOB record:


EMPL_STATUS, LOCATION, AND BUSINESS_UNIT
NOTE: You may have to use the Find search option
79

Joining Base Tables to Control Tables

Control tables are shared by all divisions and sometimes need to be joined using
multiple keys or fields.

Many control tables have a Setid field that is used to match the Setid for the division
accessing the table.

Most control tables also have an Effective Date that should be considered when
joining to another base table.

80

Many fields that have associated tables have a link next to them that allows the user
to click and automatically join this table to this field.
In this example we will join the Location_Tbl control table to the Location field in
the Job record.
Click on the Join LOCATION TBL link & click OK to the pre-selected join.

81

Now the three tables are joined together (Person_Name, Job & Location_Tbl).
Select the DESCR Field in the Location table and go to the Criteria tab in the query.
82

Here you see that the base tables have been joined together and the Effective Dates are set
to look at the most current row in the record. Because you used the join link for the location
table you do not see the joining of the location field in job with the location field in the control
table. However, it is done automatically for you in the background. This can be seen if you
look at the SQL tab.
NOTE: Because it is a control table, a manual join of the Setid should be done to eliminate
the chance of duplicate values for the same field.
83

Select the Criteria tab & click on the Add Criteria button to create a new criteria to join the
Setid field in the Location record with the Setid for location in the Job record.
The fields to be joined are shown in the example above.
84

Now we need to go to the Fields tab and edit our fields.


85

Add criteria on EMPL_STATUS to select only values of A, L, P.


Use the short translate value for the status code.
Move the Location Description next to the Location Code
Rename the Location heading text to read: Location Descr

86

Prompted Queries

PeopleSoft Query allows you to build reports that contain runtime prompts.

A runtime prompt allows you or another user to enter a value for a specific field at the time
the query is run.

The report will display only those data rows that match the criteria entered in the prompt.

This makes the query dynamic, allowing it to be used over and over again without
modifying the query to meet changing requirements.

87

Runtime Prompts
Create the following query to retrieve employee disability election information.
Record

DISABILITY_BEN

Fields

EMPLID
PLAN_TYPE

(short description)

COVERAGE_BEGIN_DT
COVERAGE_ELECT

(short description)

BENEFIT_PLAN
Order by

EMPLID

Query name

DISABILITY
88

Your Fields tab should look like this.

Save the query and Run it.

89

Results

90

A prompt is another type of criteria and it can be added from two locations: From either the
Fields tab or the Prompts tab.
Click the Prompts tab
The Prompts tab can be used to add runtime prompts and display a list of all prompts that
have been added to the query.
The Fields tab is the most common method of adding criteria and is useful when only adding
one runtime prompt.
Click the Fields tab

91

For field PLAN_TYPE, click the Add Criteria icon.


Expression 2 Type: Prompt
Expression 2: New Prompt

92

Select Heading Type: RFT Long


Heading Types are:
RFT Long
Long field name
RFT Short
Short field name
Text Anything you want
Type, Format and Length all default from the field
definition in the database.
Edit Types:
No table edit
Prompt Table
Translate Table
Yes/No Table
Prompt Name is used in translations. No need
to change this field.
Click OK twice

93

Click on the Fields Tab

Note that a prompt has been added and is represented as a bind variable.
Click Save
Click Run

94

A prompt is displayed allowing you to select or enter your criteria


Select Long-Term Disability
Click OK

95

By using a prompt, the query is dynamic based on the Plan_Type chosen for each run.

96

To add a prompt for an additional field, such as coverage election, you would simply add
another row of criteria.
Click the Fields tab
Click the Add Criteria icon for the COVERAGE_ELECT field
97

Choose Expression Type 2: select Prompt


Examine the Define Prompt section of Expression 2
Prompt

Will display the bind variable or prompt name used for this criteria

Search Icon

Will display all prompts created for this query

New Prompt

Select this hyperlink to create a new prompt to be used for this row of criteria

Edit Prompt

Use this hyperlink to edit the existing prompt used for this row of criteria

In Expression 2, select the New Prompt hyperlink


98

Heading Type: RFT Long


Click OK
Click OK

99

Examine Criteria tab for new criteria row


Click Save
Click Run

100

You now have two prompts that will be used in your criteria.
Select Plan Type prompt: Long-Term Disability
Select Coverage Election prompt: Elect
Click OK

101

Results

102

Runtime Prompts Example #2


Record

Health_Benefit

Fields

Emplid
Plan_Type

Short description

Coverage_Begin_Dt
Coverage_Elect

Equal to E

Benefit_Plan
Order By

Emplid

Query Name

OX_GBLCO_MEDICAL

103

Your Fields tab should look like this.


Save the query and run it

104

Results

105

Now, we will add a prompt to the query:

Reminders:
You can add a prompt in two ways:
- Using the Prompts tab
- Using the Fields tab (most common method when adding one runtime prompt)

Click on the Fields tab

106

For Plan_Type: Click the Add Criteria Icon


Expression 2 Type: Prompt
Expression 2: Click New Prompt

107

Select Heading Type: RFT Long


Heading Types:
RFT Long (Long field name)
RFT Short (Short field name)
Text (Anything you want)
NOTE: Type, Format and Length all
default from the field definition in the
database.

Edit Types:
- No Table edit
- Prompt Table
- Translate Table
- Yes/No Table
Unique Prompt Name is used in
translations No need to change this
field.
Click OK twice
108

Go to the Criteria tab: Note that a prompt has been added and is represented as a bind
variable.
Click Save

Click Run

109

A single prompt is displayed for you to select your specific criteria for the population you
want to retrieve
Select Medical
Click View OK

110

With the prompt, the query is dynamic based on the Plan_Type selected at run time.
111

To add a prompt for an additional field, such as coverage election, (which youve already
coded in the criteria), simply add another row of criteria.

Click the Fields tab


Click the Edit button for the Coverage_Elect field
Expression 2 Type: Prompt
Expression 2: New Prompt

112

Heading Type: RFT Long


Click OK
Click OK

Examine Criteria Tab for new criteria row


Click Save
Click Run

113

Select Plan Type: Medical


Select Coverage Election: Elect
Click OK

View RESULTS below.

114

Prompt Summary
Creating Prompts:
Prompts Tab

Useful when adding multiple prompts to one query

Criteria Tab

Useful when adding only one prompt to a query for a specified field

Editing Prompts once created, you can view them via one of the methods above
Prompts Tab

Click Edit button for the prompt you wish to edit.

Criteria Tab

Click Edit Prompt hyperlink to edit the prompt.

Deleting Prompts:

To delete a prompt, access the Prompts page and click the delete button
(minus sign) for the prompt you wish to delete. If you are using the prompt in a
row of criteria, you must remove it from the criteria before deleting it.

115

Writing Expressions
Record

Personal Data

Fields/Headings

Emplid

ID

Name

Employee Name

Sex

Gender(short desc)

Birthdate

116

Your Fields screen should look like this.


Did you remember:
- To change the description of name and sex
- To add the short description to sex
117

Select the Expressions tab


Click on Add Expression

118

Change the expression Type to Number


Use 3 as the Length
Click on the Add Field Link
Choose Birthdate from the select list

119

Insert/Enter the formula shown below in the Expression Text box


Click OK

Formula (calculates age as of the current date):


Datediff(mm,A.BIRTHDATE,getdate())/12

120

Click on the Use as Field link to include this expression to your query results

121

Change the Heading Text on the expression Line (Line 5) to Age


Click on the Run tab

122

Results

123

Adding an Expression as Criteria in the Query

Choose the Fields tab


Click on the Add Criteria icon for the expression line (Line 5)

124

Expression 1 Type: Expression


Expression 1: shows Expression
(NO change required)

Condition Type: Greater than


Expression 2 Type: Constant
Expression 2: 35

Click OK
Click on the Criteria tab
125

The expression is now part of the criteria.


The query will only select employees over the age of 35
Hit the Run Tab

126

Results

127

Você também pode gostar