Basic Query 9.0 Training Manual Basic 9.0 Query Cal State San Marcos Training Manual Table of Contents SECTION 1 ............................................................................................................................... 1 SECTION 2 ............................................................................................................................... 2 2.1 2.2 2.3 2.4 Accessing Query Manager ................................................................................... 3 Opening an Existing Query .................................................................................. 4 Running a Query ................................................................................................. 6 Setting Preferences ........................................................................................... 10 SECTION 3 ............................................................................................................................. 12 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 Selecting a Record ............................................................................................. 13 Selecting Fields .................................................................................................. 18 Removing Fields ................................................................................................ 21 Running Queries ................................................................................................ 23 Modifying Headings ........................................................................................... 26 Sorting Query Output ........................................................................................ 30 Adding Fields ..................................................................................................... 37 Using Translate Values ...................................................................................... 40 Changing Column Order .................................................................................... 45 Aggregate Functions .......................................................................................... 48 SECTION 4 ............................................................................................................................. 53 4.1 4.2 4.3 4.4 4.5 4.6 4.7 Adding Selection Criteria.................................................................................... 54 Criteria Components .......................................................................................... 59 Entering Criteria ................................................................................................ 61 Condition Type/Expression Combinations .......................................................... 65 Compound Selection Criteria and Effective Dates .............................................. 67 Effective Dating ................................................................................................. 70 Boolean Operators ............................................................................................. 72 SECTION 5 ............................................................................................................................. 86 5.1 Joining Two Tables ............................................................................................ 87 SECTION 6 ............................................................................................................................. 95 6.1 6.2 Validating Queries ............................................................................................. 95 Summary ........................................................................................................... 97 Appendix A - Table Definitions.............................................................................................. 98 Appendix B - Query Naming Convention Standards ........................................................... 99 Basic 9.0 Query Cal State San Marcos Training Manual SECTION 1 Introduction OVERVIEW The intent of this course is to demonstrate the features of PeopleSoft Query Release 8.4. This course is designed to teach users how to create queries using PeopleSoft’s Query tool via the web interface. COURSE OBJECTIVES By the end of this course, you will be able to: Open existing queries Create new queries Specify selection criteria and sorts Generate run-time prompts Send query results to Excel Perform a simple join between two tables 1 Basic 9.0 Query Cal State San Marcos Training Manual SECTION 2 Query Overview OVERVIEW This lesson reviews how to access Query, as well as how to run an existing query. You will also learn about the various components of the query definition. In later lessons, we will use this acquired knowledge to build and execute queries. SECTION OBJECTIVES By the end of this section, you will be able to: Access Query Understand new Query terminology Open an existing query Run an existing query View query results Set preferences 2 Basic 9.0 Query Cal State San Marcos Training Manual 2.1 Accessing Query Manager To provide a quick introduction to Query, you will access and run an existing query. Once you execute the query, the results will be displayed on the screen within a grid control. Once you are logged on to PeopleSoft, perform the following steps to access Query Manager. Navigation: Reporting Tools > Query > Query Manager The Query Manager page displays. From the Query Manager page you can open a query, modify an existing query, run an existing query, or create a new query. 3 Basic 9.0 Query Cal State San Marcos Training Manual 2.2 Opening an Existing Query For predefined queries, you can open and/or execute them easily. As new queries are defined, they can be saved and executed as well. Enter a part or all of the query name For this example, type SMO_GL Press the Search button The list of available queries displays Queries can be executed directly from this menu, by pressing the Run link, however, for this class we will first open the query Click the hyperlink for the SMO_GL_ACTUALS query NOTE: Only queries that have been saved as “public,” as indicated in the third column, are available to all users. “Private” queries can only be accessed by the person who created them. If you create a query for public use, it may be wise for you to save an additional copy as private, since public queries may be changed or deleted by another user who has authority to do so. 4 Basic 9.0 Query Cal State San Marcos Training Manual When the query opens, the Fields page is initially displayed. This page lists the fields to be selected by this query as well as a number of each field’s properties as pertains to the query. 5 Basic 9.0 Query Cal State San Marcos Training Manual 2.3 Running a Query There are several different ways you can run a query. In addition, there are several different places you can run the query to. For example, you can run the query to the online grid control on your monitor and from there you can download to Microsoft Excel. To run a query, select the Preview Tab at the top. Enter the run-time prompts and press the “OK” button. When the query has finished running, the results are displayed in a new window in a grid format. 6 Basic 9.0 Query Cal State San Marcos Training Manual 7 Basic 9.0 Query Cal State San Marcos Training Manual To run the output to an Excel spreadsheet click the Download to Excel hyperlink: The spreadsheet will be displayed in Excel. (See instructions for the correct settings.) 8 Basic 9.0 Query Cal State San Marcos Training Manual To save the file, click on the File/Save As from Excel and change the file type to Excel (.xls). Give the file a name and press SAVE. 9 Basic 9.0 Query Cal State San Marcos Training Manual 2.4 Setting Preferences You are able to control the look and feel of your Query Manager by setting your own preferences on your system. Click the Preferences hyperlink. The Query Preferences page allows you to control the display of records by either description or name and description. “Name and description” is selected. Do not change. The “Enable Auto Join” checkbox is used to automatically determine the join conditions when a new record component is added. Do not change. 10 Basic 9.0 Query Cal State San Marcos Training Manual 11 Basic 9.0 Query Cal State San Marcos Training Manual SECTION 3 Creating a Query OVERVIEW This lesson illustrates how to create and execute a new query. In addition, we will save and modify the query. Building on these skills, we will then make the query more complex by adding such operations as sorts, aggregate functions and Translate Table values. SECTION OBJECTIVES By the end of this section, you will be able to: Create queries Save queries Change headings Sort query output Use the Translate Table Use aggregate functions such as count and average 12 Basic 9.0 Query Cal State San Marcos Training Manual 3.1 Selecting a Record Let’s create a new query that will produce a list of Vendors. We will start with some very simple concepts and build on these skills to create a more complete and useful query. The first step in creating a query is selecting a record. For example, if you want Vendors, select the Vendor record. There are several different methods to select a record from this page. You can search by Name (shown below) or Description where either begins with (shown below) or contains certain letters. Select the Create New Query Link 13 Basic 9.0 Query Cal State San Marcos Training Manual Drop-downs show available search options Note: Refer to the last section of this guide for a list of the most frequently used records in the system. For our example, leave the drop-down values as they are and type the first few characters of the record name (“VEN” in the example shown below), and then press the Search button. Click the Add Record hyperlink next to the record to add to the query. 14 Basic 9.0 Query Cal State San Marcos Training Manual Note: For effective dated tables, you be told that an effective date criteria has been automatically added for this effective dated record. (This is not an effective dated table) Select OK. 15 Basic 9.0 Query Cal State San Marcos Training Manual Once a record has been selected, the Query page is activated. All fields contained in the selected record, VENDOR, are displayed. 16 Basic 9.0 Query Cal State San Marcos Training Manual Activity #1 - To create a list of all Vendors, select the VENDOR record using one of the navigation options defined. 17 Basic 9.0 Query Cal State San Marcos Training Manual 3.2 Selecting Fields The next step in defining a query is to select the fields that will comprise the output columns. Navigation options for selecting fields: Option 1: Manually select individual fields by clicking on the desired checkboxes to the left of the field(s). Hint: Fields are in record order. To view the fields in Alpha order press the A/Z tab. Or, click Ctrl/F and type the name. 18 Basic 9.0 Query Cal State San Marcos Training Manual OR Option 2: Select all fields by pressing Check All Fields button. Warning: Some tables are so large that selecting all fields can be very resource-intensive and cause your query to take much longer to run. Do not use this option on large tables! 19 Basic 9.0 Query Cal State San Marcos Training Manual Activity #2 - Create a Vendor list, select the SETID, VENDOR_ID, VENDOR_NAME_SHORT, NAME1, VENDOR_STATUS, VENDOR_CLASS, VENDOR_PERSISTENCE, and VNDR_STATUS_PO fields using one of the navigation options defined. Follow the example as a guideline. Select the Fields page to view the selected fields and their properties. The column order is indicated in the column titled “Col”. The sequence number represents the left to right order of the displayed fields in the query output. 20 Basic 9.0 Query Cal State San Marcos Training Manual 3.3 Removing Fields To remove a field from your query output, press the “Delete” (“-“) button on the field’s line. 21 Basic 9.0 Query Cal State San Marcos Training Manual Activity #3 - Modify the Vendor list by removing the VENDOR_PERSISTENCE and VNDR_STATUS_PO fields, so that the remaining query fields are as shown below. 22 Basic 9.0 Query Cal State San Marcos Training Manual 3.4 Running Queries Prior to running a new query, you will want to save it. Press the Save button at the bottom of the page to save the new query. Enter the query name (use a prefix of “SMO_”, to indicate a San Marcos custom query), a short description, the query type (in this case “User”), and the owner (in this case “Private”). For these exercises ONLY, also include your initials at the end of the query name and name the query SMO_VNDR_LIST_your inititals). Initials are not required in Production. Include your initials in the query name. See Appendix B for Recommended naming conventions. Note: Be sure to avoid using spaces in the query name or you will receive an error message. 23 Basic 9.0 Query Cal State San Marcos Training Manual Notice that the query name changes from “New Unsaved Query” to “SMO_VNDR_LIST_ (your initials)” 24 Basic 9.0 Query Cal State San Marcos Training Manual Click the Preview Tab to execute the query. The output will be displayed in the same window: To return to the query, select the Fields Tab. 25 Basic 9.0 Query Cal State San Marcos Training Manual 3.5 Modifying Headings The text listed in the “Heading Text” column will be used for the headings in your query output to the grid control and Excel. Let’s change the heading for VENDOR_ID to “Vendor ID” and the heading for VENDOR_STATUS to “Vendor Status”. Press the Edit button on the field line you wish to change the heading for. 26 Basic 9.0 Query Cal State San Marcos Training Manual To modify field headings: In the “Heading” group box, click on the “Text” radio button Select and click in the “Heading Text” field Type new heading text into the text box Press the OK button 27 Basic 9.0 Query Cal State San Marcos Training Manual Save the changes to the query and rerun it. The modified headings are shown in the resultant output. 28 Basic 9.0 Query Cal State San Marcos Training Manual Activity #4 - Modify the Vendor list changing the headings of the VENDOR_ID and VENDOR_STATUS fields to be “Vendor ID” and “Vendor Status.” SAVE your changes and rerun your query. Verify your results with the above example. 29 Basic 9.0 Query Cal State San Marcos Training Manual 3.6 Sorting Query Output The numbers in the “Ord” column represent which fields your query is using to sort the output. Unless you specify a specific sort order, the query will list the results in the order that the data is retrieved from the database. Let’s sort the output by the NAME field. There are two ways to specify the Sort Order: From the Fields tab press the Edit button for the field to change sort order. 30 Basic 9.0 Query Cal State San Marcos Training Manual Specify the sort order in the “Order By Number” field in “Order By” group box. Press OK. OR 31 Basic 9.0 Query Cal State San Marcos Training Manual From the Fields tab press the Reorder/Sort button for the field to change sort order. 32 Basic 9.0 Query Cal State San Marcos Training Manual Specify the sort order in the “Order By Number” field. Press OK. 33 Basic 9.0 Query Cal State San Marcos Training Manual The number “1” now displays in the “Ord” column for NAME. More than one field may be selected for sort criteria. For example, you could sort the query by NAME within STATUS. When you select more than one field to sort by, the number displayed in the “Ord” column indicates the sequence in which the fields are used to sort the output. For now, we are putting this query in NAME sequence only. NOTE: The system will sort the output in ascending order for the field. If you want to sort the output in descending order, click on the “Descending” checkbox. If you choose to sort the output in descending order, a ‘D’ will be displayed in the “Ord” column. Save your changes to query and rerun. 34 Basic 9.0 Query Cal State San Marcos Training Manual The modified sort order is shown in the resultant output. 35 Basic 9.0 Query Cal State San Marcos Training Manual Activity #5 - Sort the query by NAME in descending order. Follow the above example as a guideline. 36 Basic 9.0 Query Cal State San Marcos Training Manual 3.7 Adding Fields In order to expand our Vendor list, let’s add the Address Sequence Number Order and Entered fields. By sorting the display of field names listed on the Query page in alphabetical order, it will be easy to find the new fields to add to the query. Go to the Query tab Press the AZ button to display field names in alphabetical order: Now that the fields are sorted alphabetically, find the ADDR_SEQ_NUM_ORDR and ENTERED_BY fields. SAVE changes to the query and rerun. 37 Basic 9.0 Query Cal State San Marcos Training Manual The new fields are shown in the resultant output. 38 Basic 9.0 Query Cal State San Marcos Training Manual Activity #6 - Add the fields ADDR_SEQ_NUM_ORDR and ENTERED_BY to your query. Follow the above example as a guideline. 39 Basic 9.0 Query Cal State San Marcos Training Manual 3.8 Using Translate Values When you scroll to the right of the query control grid, you will notice that the field VENDOR_STATUS contains a code which indicates the status of the Vendor. These codes are defined in the Translate Table, which also contains a more meaningful description of what the code means. You may choose either the 10 character short description, or 30 character long description for the field. When a code is translated, the description displays in the query output instead of the code. We will modify the query to translate the code for VENDOR_STATUS to the long description. From the Fields page press the Edit button for the field to employ use of translate values. Select the “Long” radio button in the “Translate Value” group box and the “Field” radio button in the “Effective Date for Short/Long” group box. Select the EFFDT field in the drop-down box. Press OK. 40 Basic 9.0 Query Cal State San Marcos Training Manual NOTE: Notice that there is now an “L” in the “XLAT” column on the VENDOR_STATUS line. 41 Basic 9.0 Query Cal State San Marcos Training Manual Save changes to the query. Rerun the query. 42 Basic 9.0 Query Cal State San Marcos Training Manual Notice that in the “Status” column, you now see the translate value descriptions. 43 Basic 9.0 Query Cal State San Marcos Training Manual Activity #7 – Change the VENDOR_STATUS field to the Long Translate value. Also, change the VENDOR_CLASS to show the Long Translate value. Follow the above example as a guideline. 44 Basic 9.0 Query Cal State San Marcos Training Manual 3.9 Changing Column Order Often it is necessary to rearrange the order in which the columns display to achieve the desired output. To change the column order, follow the steps below. Two navigation options for changing the column order: OR Option 1: To change the order for a single field, press the Edit button to go to the Edit Field Properties page. Specify new column number in “Column” group box. Option 2: To change multiple fields, press the Reorder/Sort button. Multiple field changes Single field changes 45 Basic 9.0 Query Cal State San Marcos Training Manual Sort order Indicate new column order. Specify new column sequence numbers in the “New Column” fields. Save changes to the query and rerun. 46 Basic 9.0 Query Cal State San Marcos Training Manual Activity #8 – Change the column order of your fields to display “NAME1” before VENDOR_NAME_SHORT. 47 Basic 9.0 Query Cal State San Marcos Training Manual 3.10 Aggregate Functions An aggregate function allows the user to perform various predefined summary options such as counting and averaging. To establish an aggregate function, press the Edit button next to the field to which you are going to apply the aggregate. This will take you to the Edit Field Properties page. Select the radio button in the “Aggregate” group box for the aggregate function you wish to apply. NOTE: In order to undo an aggregate function, follow the instructions above and choose the radio button labeled “None”. Important Note: Aggregates cannot be used to count or sum in every type of query. If you are selecting multiple fields that will generate unique and distinguishing results, the count/sum may not produce the totals you are expecting. For example, the Count feature cannot be used in the above query to count the number of Vendors. The data being requested for each row is unique, so there is no way for the system to present the unique data and also to provide a count. Let’s look at an example where an aggregate can be used. 48 Basic 9.0 Query Cal State San Marcos Training Manual Using the VENDOR record, we will create a new query that counts the Address for each Vendor. Click on New Query hyperlink to create a new query Add the VENDOR record to query Select the VENDORID field Select the ADDR_SEQ_NUM_ORDR field Press Edit button on ADDR_SEQ_NUM_ORDR field line to go to the Edit Field Properties page 49 Basic 9.0 Query Cal State San Marcos Training Manual Select the “Count” radio button in the “Aggregate” group box. Preview the query. 50 Basic 9.0 Query Cal State San Marcos Training Manual 51 Basic 9.0 Query Cal State San Marcos Training Manual Activity #9 – Create a new query using the VENDOR table. Select VENDOR_ID and ADDR_SEQ_NUM_ORDR. Count the number of Address sequences for each Vendor. Follow the above example as a guideline. 52 Basic 9.0 Query Cal State San Marcos Training Manual SECTION 4 Using Selection Criteria and Prompts OVERVIEW In this lesson you will learn how to specify selection criteria in a query. Selection criteria are used to restrict the rows selected from the database when the query is executed. In addition, you will learn how to create run-time prompts. OBJECTIVES By the end of this section, you will be able to: Create selection criteria Create run-time prompts 53 Basic 9.0 Query Cal State San Marcos Training Manual 4.1 Adding Selection Criteria Criteria are “filters” that are used to select only specific rows of data from the database. Criteria can be established from both the Fields and Criteria pages. Using our Vendor list as an example, you may want to create a listing of Vendors by SetID or only active Vendors. The query we created in the previous section gives us all Vendors. Let’s now add selection criteria to the query. We do not want to modify the query we previously created and saved, so we will make a copy of the query first by doing a “Save As” command. Open the Vendor list query called SMO_VNDR_LIST_(your initials) 54 Basic 9.0 Query Cal State San Marcos Training Manual Click the Save As hyperlink and change the query name to SMO_VNDRS_ACTIVE_SMCMP_(your initials). Click OK. 55 Basic 9.0 Query Cal State San Marcos Training Manual The query looks like this. Option 2 Option 1 There are a couple of different ways to add criteria to a query. Both of these approaches will take you to the Edit Criteria Properties page. Option 1: Click on the “funnel-plus” button in the “Add Criteria” column for the individual field for which you want to add a criterion. Option 2: Go to the Criteria page and press the Add Criteria button. 56 Basic 9.0 Query Cal State San Marcos Training Manual Using the first method will auto-populate some fields for you. You will need to select the Condition Type and Define the Constant. 57 Basic 9.0 Query Cal State San Marcos Training Manual However, the second method is more comprehensive. Navigating to the Criteria page we see. Note: This method is more advanced and will not be reviewed in this basic Query Training guide. However, below defines the components and their use. 58 Basic 9.0 Query Cal State San Marcos Training Manual 4.2 Criteria Components The Criteria page together with the Edit Criteria Properties page, allow you to define criteria expressions to selectively retrieve information. Criteria Logic: Logic Component Logical Expression 1 Condition Type Expression 2 Definition Contains the Boolean operator that represents how the criteria rows are evaluated. Blank for the first criteria, subsequent rows default to AND but can be changed to OR. Used to specify what you are comparing. State how your Expression 1 is to be compared with your Expression 2. You can compare the Expression 1 to a constant, a field from another record, an expression, a subquery, or values entered using a run-time prompt. 59 Basic 9.0 Query Cal State San Marcos Training Manual Command buttons Logic components Command Buttons: The buttons on this page are used to manipulate query criteria. Button Add Criteria Definition Add Criteria Delete Remove existing criteria Edit Edit existing criteria Group Criteria Add or remove parentheses 60 Basic 9.0 Query Cal State San Marcos Training Manual 4.3 Entering Criteria Let’s add criteria to our query to select Vendors with a SETID – SMCMP. To enter criteria for the Vendor SETID field, press the Add Criteria button. This will take you to the Edit Criteria Properties page. The “Field” radio button is selected in the “Choose Expression 1 Type” group box. Leave the default selection. The Condition Type defaults to “equal to”. Leave it set to the default value. The “Constant” radio button defaults in the “Choose Expression 2 Type” group box. Leave the default value for the moment. Enter the SETID you want to restrict VENDORS to in the “Constant field” within the “Define Constant” group box within the “Expression 2” group box. Click OK. 61 Basic 9.0 Query Cal State San Marcos Training Manual Save the query and rerun it. 62 Basic 9.0 Query Cal State San Marcos Training Manual The results displayed will be limited to Vendors with SETID equal SMCMP. Activity #10 - Add the criteria for SETID in your query. Limit the results to “SMCMP.” Follow the above example as a guideline. 63 Basic 9.0 Query Cal State San Marcos Training Manual 64 Basic 9.0 Query Cal State San Marcos Training Manual 4.4 Condition Type/Expression Combinations Each Condition Type uses specific expressions for the “Expression 2” group box. Condition types will be covered in more detail in Section 4.13. Condition Type equal to not equal to greater than not greater than less than not less than in list not in list between not between like not like exists not exists is null is not null in tree not in tree Expression 2 constant field expression subquery prompt list subquery constant-constant constant-field constant-expression field-constant field-field field-expression expression- constant expression-field expression-expression constant prompt subquery tree option 65 Basic 9.0 Query Cal State San Marcos Training Manual 66 Basic 9.0 Query Cal State San Marcos Training Manual 4.5 Compound Selection Criteria and Effective Dates Often you will have to create a query that requires multiple selection criteria against one or more fields. When you have multiple conditions, you must use one of the Boolean operators to relate one criterion to another. The operators available on the Criteria page are AND, OR, NOT, and parentheses. The operators AND, OR, and NOT are used to show the relationship of one criteria row to another. Parentheses are used to further define the relationship and define the order in which the criteria are evaluated. If you do not use parentheses, the criteria are evaluated in the order listed. Let’s add criteria to qualify on VENDOR_STATUS as well as VENDOR_CLASS in our query. From the Fields page, press the “Add Criteria” icon on the VENDOR_STATUS line. Enter “A” into the “Constant” field within the “Expression 2” group box. From the Fields page, press the “Add Criteria” icon on the VENDOR_CLASS line. Enter “R” into the “Constant” field within the “Expression 2” group box. Press the OK button. Resave the query and rerun. 67 Basic 9.0 Query Cal State San Marcos Training Manual NOTE: Notice that the output displays rows with a SETID equal to SMCMP, Vendor Status equal to “Approved” AND Vendor Class equal to R. In addition, the output is sorted by name in ascending order. 68 Basic 9.0 Query Cal State San Marcos Training Manual Activity #11 - Add the criteria for VENDOR_STATUS equal to “A” and VENDOR_CLASS equal to “R” to your query. Follow the above example as a guideline. 69 Basic 9.0 Query Cal State San Marcos Training Manual 4.6 Effective Dating Special attention needs to be given to the use of effective dates in the system. The system will attempt to automatically include the effective date in your query based on a default. In most situations, this will be the most current row of information that is less than or equal to the current date. However, this may not be the information that you need for your report. Let’s look at various issues with respect to effective dates: 1. Operators that will extract one row of table information by effective date: Only certain operators will obtain one row of effective-dated information. These are the following: Eff Date < Eff Date <= Eff Date > Eff Date >= First Eff Date Last Eff Date These operators tell the system to obtain the max row (last row, or very first row in the case of “First Eff Date”) of data that meets the requested criteria. 70 Basic 9.0 Query Cal State San Marcos Training Manual If you are not using the operators that limit the number of rows retrieved for an effective date, you may get multiple rows of information back for each record. For instance, if you asked for all effective dates less than July 1, 2004, the system would retrieve one row of information for each row it found prior to that date. 2. Situations where you will have two effective-date criteria for the same field: There will be certain situations where you want, for example, the most current row of information, but only for Funds that have transactions between a specified date range. In this case, you would need to use the operator to obtain the row less than or equal to the current date, and a second criteria to limit only those rows within the requested timeframe. If you only ask for effective dates between the timeframes, you may get multiple rows for each Fund. 3. Multiple Transactions on the Same Date: Remember that the system stores multiple transactions on the same date. These are distinguished by a sequence number. However, if you used one of the operators above that only bring back a single row of data, you may not capture all the needed transactions. For example, say that you want to create a report of all new Funds as of July 1, 2004. If your effective date criteria was “Effective Date <= July, 1, 2004”, the system would only return the last transactions entered that day. The Funds may have been entered prior to another action/reason on the same day. 4. Frequency of table update: Remember that some tables hold system values are only updated infrequently and that Fund data may not yet have transactions that reflect the latest system table values. 5. Joins (which will be discussed in detail later): Remember to check the automatic defaults for effective-dating that the system performs when doing a join. It will often attempt to make the effective date of the second table less than or equal to that of the first table’s effective date. This may not be accurate, depending on the tables you are using, and the information you are trying to retrieve. 71 Basic 9.0 Query Cal State San Marcos Training Manual 4.7 Boolean Operators When you need to use multiple fields or the same field more than once for selection criteria, the operators of OR, NOT or parentheses may also have to be selected. If you wanted to see all Active Vendors excluding those who are not in VENDOR_CLASS equal to “R”, follow these steps: From the Criteria page, on the VENDOR_STATUS line, change the value in the “Logical” drop-down list from “AND” to “AND NOT” 72 Basic 9.0 Query Cal State San Marcos Training Manual OR- Change the Condition Type to “Not Equal To.” Note: 2nd method – which produces the same results 73 Basic 9.0 Query Cal State San Marcos Training Manual Resave the query and rerun it. NOTE: Notice that the output displays rows with a VENDOR_STATUS equal to “Approved” AND a VENDOR_CLASS NOT equal to “R” only. In addition, the output is sorted by name in ascending order. 74 Basic 9.0 Query Cal State San Marcos Training Manual Now let’s modify the criteria to select Vendors that are Approved or have a Vendor Class equal to “R”. From the Fields page, change the Sort to Vendor Status, Descending. Press the OK button From the Criteria page and on the VENDOR_STATUS line, change the condition type to “Equal To”. From the Criteria page and on the VENDOR_STATUS line, change the value in the “Logical” drop-down list to “OR” from “AND” 75 Basic 9.0 Query Cal State San Marcos Training Manual Resave the query and rerun: NOTE: Notice that the output displays rows with a Vendor Status equal to “A” or Vendor Class equal to “R”. In addition, the output is sorted by Vendor Status in descending order. 76 Basic 9.0 Query Cal State San Marcos Training Manual Activity #12 – Follow the steps above and add the criteria to select Approved Vendors or Vendors with a Class of “R”. 77 Basic 9.0 Query Cal State San Marcos Training Manual 4.8 Reordering Criteria To change the order of the selection criteria, you must delete all criteria and then add back each criterion in the desired order. 78 Basic 9.0 Query Cal State San Marcos Training Manual 4.9 Removing Criteria Let’s remove the criteria row for the SETID, Vendor Status, and Vendor Class. In order to accomplish this, follow the steps listed below: Press Press Press Press the Delete button (“-“) on the SETID line the Delete button (“-“) on the VENDOR_STATUS line the Delete button (“-“) on the VENDOR_CLASS line SAVE to save the changes and rerun the query. 79 Basic 9.0 Query Cal State San Marcos Training Manual Activity #14 – Follow the steps above and delete all criteria. Also, change the Sort back to Sort by NAME1, ascending. 80 Basic 9.0 Query Cal State San Marcos Training Manual 4.10 Run-time Prompts There are times when you may want to use a different value for a field each time the query is run. An example of this might be a Vendor listing report for a particular SETID. A run-time prompt allows you to enter a value for a specific field at the time the query is executed. This eliminates the necessity of having many different queries that are virtually the same except for one or more variables. Run-time prompts are available for all expression types except is null and in tree, as well as their negative counterparts. You can have multiple prompts in a query. Let’s establish a run-time prompt on the SETID field. From the Fields page, press the Add Criteria button Choose the default, SETID field for the “Expression 1 group box” Select the “Prompt” radio button in the “Choose Expression 2” group box: Click on the New Prompt hyperlink in the “Define Prompt” group box within the “Expression 2“ group box: 81 Basic 9.0 Query Cal State San Marcos Training Manual NOTE: If you would like to change the run-time prompt heading, then click on the “Heading Type” drop-down list and select “Text”. Then enter the new heading in the “Heading Text” text box. Click the OK button to return to the Edit Criteria Properties page Click the OK button to return to the Fields page 82 Basic 9.0 Query Cal State San Marcos Training Manual Click on the Prompt tab to view the Prompt criteria Resave the query and rerun. 83 Basic 9.0 Query Cal State San Marcos Training Manual Enter the SETID search for and press the OK button: 84 Basic 9.0 Query Cal State San Marcos Training Manual Activity #15 –Build a run-time prompt on the SETID field. Follow the above example as a guideline. 85 Save the query. Basic 9.0 Query Cal State San Marcos Training Manual SECTION 5 Creating a Simple Join OVERVIEW In this lesson you will learn how to create a query utilizing a simple join between two tables. This technique is used when a query requires data that is not all contained in one table. OBJECTIVES By the end of this section, you will be able to: Create a query in which two tables are joined on common keys. 86 Basic 9.0 Query Cal State San Marcos Training Manual 5.1 Joining Two Tables Joining tables greatly extends Query’s reach by enabling the user to combine data from multiple tables into a single query. For example, the VENDOR table contains the VENDOR name data, but not the Vendor Addresses. In order to include both the Vendor Name and Addresses on the same report, you would have to join the VENDOR table to the VENDOR_ADDR table. Most of the time, it is important to join on all common keys to prevent unexpected results and performance problems. Fortunately, Query does a lot of work for us. In the following example, the Query tool takes care of joining on common keys for us. Create a new query by clicking the New Query hyperlink Add the VENDOR table to the query Select the SETID, VENDOR_ID, NAME1, and the VENDOR_STATUS fields: 87 Basic 9.0 Query Cal State San Marcos Training Manual Let’s join the VENDOR_ADDR table to get the address for the Vendors. Click on the Records Tab. Enter VEN in the Search Criteria. Select the Join Record Link for the VENDOR_ADDR table. 88 Basic 9.0 Query Cal State San Marcos Training Manual The system proposes the join criteria. Click Add Criteria to accept the default; in this case the SETID and VENDOR_ID from the VENDOR table should equal the SETID and VENDOR_ID from the VENDOR_ADDR table 89 Basic 9.0 Query Cal State San Marcos Training Manual The VENDOR_ADDR table will be added as Table “B” Select the ADDRESS_SEQ_NO, ADDRESS1, CITY, STATE, and POSTAL fields. 90 Basic 9.0 Query Cal State San Marcos Training Manual The Fields page will look like this: Notice that the system identifies fields from the 2 tables by including the prefix of “A” or “B” in front of the field names. 91 Basic 9.0 Query Cal State San Marcos Training Manual Go to the Criteria tab and see the new criteria. Using this method, the system displays the join criteria here The Criteria page will look like this. Note: Always pay special attention to how the effective date logic is added. Often, you will not want the default logic of <= the field from the other table. In many cases, the effective date should be <= the current date! Go to the Fields Tab, Sort by NAME1. Add criteria to the SETID field, restricting the query to data where SETID = SMCMP only. Save the new query as SMO_VNDR_ADDR_your initials. Run the new query. 92 Basic 9.0 Query Cal State San Marcos Training Manual 93 Basic 9.0 Query Cal State San Marcos Training Manual Activity #16 – Build a new query using the VENDOR table. Select the SETID, VENDOR_ID, NAME1, and the VENDOR_STATUS fields. Sort by NAME1. Select SETID equal to SMCMP. Join the table to the VENDOR_ADDR table and select the ADDRESS_SEQ_NO, ADDRESS1, CITY, STATE, and POSTAL fields. Use the above example as a guide. 94 Basic 9.0 Query Cal State San Marcos Training Manual SECTION 6 6.1 Validating Queries Your query will extract data from the system exactly the way you have asked for it. However, if there is a problem in the way you ask for the information (i.e. your criteria), you may get unexpected results. Here are some hints and suggestions to help ensure you obtain accurate information: The safest way to build a query is to do it incrementally. In other words, save and run your query as you add each criteria and look at the count of the records after each run. Make sure that the last criteria you added did not suddenly exclude needed records. Be very careful when adding parenthesis to your criteria. Data will be included/excluded inadvertently if your logic is incorrect. Make sure you are using the correct fields to limit your criteria. If you are not familiar with how the data is entered into the system, call the team lead responsible for the information or SOD, to find out the best way to do your search. This knowledge often comes with experience using query and the tables. Not every field on each table is populated. Be careful not to use criteria on a field that has no values on the table you are using. The best way to find this out is to select the field first and run it without any criteria, in order to view what the actual data on the table looks like. Then, go back and input your criteria. Where possible, it’s sometimes helpful to run a separate query from a table that has similar information to compare results. Be extremely careful when using effective-dating (refer to Section 4.6). Remember that tables that hold system values are only updated infrequently and that certain data may not yet have transactions that reflect the latest system table values. Remember to check the automatic defaults for effective-dating that the system performs when doing a join. 95 Basic 9.0 Query Cal State San Marcos Training Manual If you are not using the operators that limit the number of rows retrieved for an effective date, you will get multiple rows of information back for each record. Remember that even when you know the exact date the transaction occurred, the action you are looking for may be one of multiple transactions stored for that date. 96 Basic 9.0 Query Cal State San Marcos Training Manual 6.2 Summary Congratulations! You have now gotten your “learner’s permit” to try your hand at creating your own reports. A few words of caution: Do not attempt to join more than two tables together until you have taken the Advanced Query class. Do not use any tables that are not referenced in the attached Appendix without first checking with SOD support. Do double-check your effective dates and verify your data by cross-checking it with other table information, if possible. Do call SOD if you have any questions, or experience any problems with the system in obtaining results! 97 Basic 9.0 Query Cal State San Marcos Training Manual Appendix A - Table Definitions See handout 98 Basic 9.0 Query Cal State San Marcos Training Manual Appendix B - Query Naming Convention Standards Ie: SMO_AP_INVOICES_PAID Custom Queries will always begin with SMO The application the query is for: AP = Accounts Payable VNDR = Vendor Master PO = Purchase Orders REQ = Requisitions GL = General Ledger BD = Budget COA = Chart Of Accounts Descriptive Title 99