Presentation on theme: "1 INTRODUCTION TO PEOPLESOFT QUERY Revised: August 2008."— Presentation transcript:
1 INTRODUCTION TO PEOPLESOFT QUERY Revised: August 2008
2 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
3 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
4 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
6 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
7 Note: –The list of query names & descriptions –Ownership (Public or Private) –Edit, Run to HTML, and Excel hyperlinks
8 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
9 This takes us to the Fields tab of the query Well take a closer look at this later Click the Run Tab
14 Creating a New Query Follow along with me on this exercise Navigate to: - Reporting Tools > Query > Query Manager - Click on Create New Query
15 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
16 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
17 Note: –Folder icon –Alias Record –Hierarchy Join –Minus Button Fields: –Check box(es) –Key Symbol –Field names –Criteria icon –Join Record Names
18 Select the Fields Click on the checkboxes for the following fields: –EMPLID –NAME –SEX –Birthdate Click on the Fields tab
19 Col Record.Fieldname Format Ord XLAT Agg Heading Text Add Criteria Edit Delete NOTE the following headings:
20 Edit Field Properties Locate the SEX field Select Edit
21 Your edit choices: Heading –No Heading –Text –RFT Short –RFT Long –Heading Text –Unique Field Name Aggregate values Translate Value –None –Short –Long
22 Edit the data as follows: Heading: Text Heading Text: Gender Aggregate: None Translate Value: Short Click OK
23 Click on Reorder/Sort Move Birthdate to Col 3 In the New Order By column: Make Sex sort order 1 Click OK
24 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
25 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.
26 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
27 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
28 Enter: Query Name: OX_GBLCO_EE_LIST_INITIALS Description: General Info About Employees Owner: Public Click OK Then click the Properties link (at bottom)
29 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
30 Examine your data Note the Download to Excel option XClose this window by clicking the X in the upper right corner
31 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:
32 Saving your query as a favorite Check the Select box Click on the Action drop down arrow Select Add to Favorites Click GO
33 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)
34 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). RecordEMPLOYMENT Fields/HeadingsEMPLIDEmployee ID HIRE_DTHire Date TERMINATION_DTTermination Date LAST_DATE_WORKEDLast Date Worked SUPERVISOR_IDSupervisor ID Order byTERMINATION_DTdescending Query NameHIRE_TERM_QRY
35 Did you remember to: –Change field headings –Order by termination date in decending order Click on the New Query hyperlink
36 Individual Activity #2 You have been asked to produce an updated list of employees emergency contacts. RecordEMERGENCY_CNTCT Fields/HeadingsEMPLIDEmployee ID CONTACT_NAMEContact Name RELATIONSHIP Relationship (short translate description) PRIMARY_CONTACTPrimary Contact PHONEPhone Order byEMPLID CONTACT_NAME Query NameEMER_CNTCTS
37 Did you remember to: –Change headings? –Use short translate value for Relationship? –Order by EmplID and Contact Name? Click on the New Query hyperlink
38 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
39 Selection Criteria Create a basic query to capture employee data and save the query without running it. RecordPERSONAL_DATA FieldsNAME EMPLID MAR_STATUS(short description) Order byNAME Query Name/DescriptionCRITERIACriteria for Employees
40 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.
41 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
42 Condition Types BetweenNot between Equal toNot equal to Greater thanNot greater than In listNot in list In treeNot in tree Is nullIs not null Less thanNot less than LikeNot like
43 Note the different Expression 2 Types: –Field –Expression –Constant –Prompt –Subquery Click the Cancel button Click the Query tab
44 Find the field: Sex Click the Add Criteria icon (funnel)
45 Select Condition Type: equal to Expression type: Constant Expression 2: F Click OK
46 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
48 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
49 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
50 Click Save Click Run NOTE the Logical drop down list (And/Or) for your criteria
51 You now have a female employees who have a capital D in their name RESULTS
52 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. RecordEMPLOYMENT FieldsEMPLID BUSINESS_TITLE HIRE_DT Order byHIRE_DT(descending) Query Name/ DescriptionBusiness_TitleManager Business Title Query
53 Results: NOTE: Some fields are case sensitive which will impact your results
55 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.
56 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.
57 Effective Dates Click the New Query link Record: JOBCODE_TBL Click Add Record Click OK in dialog box Select the Criteria tab
59 Four effective dated comparisons: –Effective Date < –Effective Date <= –Effective Date > –Effective Date >= Do Not Use: –First Effective Date –Last Effective Date
60 Individual Activity #4 Create a query that lists the last current job actions as of the current date for your employees. RecordJOB Fields/HeadingsEMPLIDID DEPTID (column 2)Dept ID JOBCODEJob Code ACTION (short description)Action ACTION_REASONReason EFFDTEffective Date LOCATIONLocation ANNUAL_RTAnnual Rate Order byEMPLID CriteriaAnnual salary of $50,000 or more (enter 50000) Compensation Frequency of monthly (Enter M) Query NameOX_BN_CUR_ACTION_XX
64 Using Aggregate Functions Five aggregate functions are available: –Average –Count –Max –Min –Sum
65 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
70 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
71 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.
72 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.
73 Types of Joins Record Hierarch 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 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.
74 Join Example RecordPerson_Name FieldsEmplid Name Create the following new Query:
75 FIELDS Tab Return to Records Tab Type in Job & Select the Join Record link next to the Job table
77 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.
78 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.
79 Select the following Fields from the JOB record: EMPL_STATUS, LOCATION, AND BUSINESS_UNIT NOTE: You may have to use the Find search option
80 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.
81 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.
82 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.
83 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.
84 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.
85 Now we need to go to the Fields tab and edit our fields.
86 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
87 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.
88 Runtime Prompts RecordDISABILITY_BEN FieldsEMPLID PLAN_TYPE(short description) COVERAGE_BEGIN_DT COVERAGE_ELECT(short description) BENEFIT_PLAN Order byEMPLID Query nameDISABILITY Create the following query to retrieve employee disability election information.
89 Your Fields tab should look like this. Save the query and Run it.
91 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
92 For field PLAN_TYPE, click the Add Criteria icon. Expression 2 Type: Prompt Expression 2: New Prompt
93 Select Heading Type: RFT Long Heading Types are: –RFT LongLong field name –RFT ShortShort field name –TextAnything 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
94 Note that a prompt has been added and is represented as a bind variable. Click Save Click Run Click on the Fields Tab
95 A prompt is displayed allowing you to select or enter your criteria Select Long-Term Disability Click OK
96 By using a prompt, the query is dynamic based on the Plan_Type chosen for each run.
97 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
98 Choose Expression Type 2: select Prompt Examine the Define Prompt section of Expression 2 In Expression 2, select the New Prompt hyperlink PromptWill display the bind variable or prompt name used for this criteria Search IconWill display all prompts created for this query New PromptSelect this hyperlink to create a new prompt to be used for this row of criteria Edit PromptUse this hyperlink to edit the existing prompt used for this row of criteria
106 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
107 For Plan_Type: Click the Add Criteria Icon Expression 2 Type: Prompt Expression 2: Click New Prompt
108 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
109 Go to the Criteria tab: Note that a prompt has been added and is represented as a bind variable. Click Save Click Run
110 A single prompt is displayed for you to select your specific criteria for the population you want to retrieve Select Medical Click View OK
111 With the prompt, the query is dynamic based on the Plan_Type selected at run time.
112 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
113 Heading Type: RFT Long Click OK Examine Criteria Tab for new criteria row Click Save Click Run
114 Select Plan Type: Medical Select Coverage Election: Elect Click OK View RESULTS below.
115 Prompt Summary Creating Prompts: Editing Prompts – once created, you can view them via one of the methods above 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. Prompts TabUseful when adding multiple prompts to one query Criteria TabUseful when adding only one prompt to a query for a specified field Prompts TabClick Edit button for the prompt you wish to edit. Criteria TabClick Edit Prompt hyperlink to edit the prompt.
116 Writing Expressions RecordPersonal Data Fields/HeadingsEmplidID NameEmployee Name SexGender(short desc) Birthdate
117 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
118 Select the Expressions tab Click on Add Expression
119 Change the expression Type to Number Use 3 as the Length Click on the Add Field Link Choose Birthdate from the select list
120 Formula (calculates age as of the current date): Datediff(mm,A.BIRTHDATE,getdate())/12 Insert/Enter the formula shown below in the Expression Text box Click OK
121 Click on the Use as Field link to include this expression to your query results
122 Change the Heading Text on the expression Line (Line 5) to Age Click on the Run tab