STIDistrict Query (Basic) Creating a Basic Query To create a basic query in the Query Builder, open the STIDistrict workstation and click on Utilities Query Builder. When the program opens, database objects called Views are displayed in the top left window of the form. These views are designed to reference data in the STIDistrict database and then display the data in a way that is easier for users to understand. To expand the items listed as views, check the All Tables and Views box, located just below the views. This will allow queries to be built for any data in the STIDistrict database. To build a simple query: While in the Design screen, select a view or table from those listed at the top left. Drag and drop into the empty space to the right of the list. Quick Reference Guide STI_1106071235 STIDistrict Query (Basic) 1
Select the fields to be included in the query by checking the box to the left of each desired field description. As fields are selected, they will appear in the list at the bottom of the screen. Note: Check the first box, labeled with an asterisk (*), to select all fields in the view for output to the query. Sort the data by clicking once in the Sort Type field of the row to sort by. Then choose either Ascending or Descending order. The sort order will be determined by the value displayed in the Sort Order column. Use the Criteria column to select specific records from the database. The syntax for entering selection criteria in this field will be as follows: o = XXX: Use this formula to select only records with the value XXX in the row selected. o > XXX: Use this formula to select records with a numeric field value greater than XXX. o < XXX: Use this formula to select records with a numeric field value less than XXX. Quick Reference Guide STI_1106071235 STIDistrict Query (Basic) 2
Click on the Execute button in the toolbar at the top of the query screen to run the query. The results screen will appear, listing the found queried data in columns. Note: Click on any column label to re-sort the data by the values in that column. To make changes to the query, click on the Design tab and change the query setup as needed. Click on the Save Query button to save the query for future use. After a query has been saved, it will appear on the Query List menu in STIDistrict. Click on the Create New Query button to create a new query. Click on the Close button to close the program. Quick Reference Guide STI_1106071235 STIDistrict Query (Basic) 3
Setting Criteria Options Follow the instructions to create a basic query (see above), then perform the following steps: In the grid in the lower half of the screen, locate the field you wish to set criteria against. Follow the row across to the Criteria column. Type the criteria for the query into the cell that intersects the row for the data, and the Criteria column. The Query Builder uses Transact SQL (T-SQL) syntax rules. Examples are listed at the end of this document. Note: Use the Tab key to tab out of the Criteria field. Setting Sorting Options Follow the instructions above to create a basic query and set criteria options, then perform the following steps to sort the data: In the grid in the lower half of the screen, locate the field you wish to sort. Follow the row across to the Sort Type column. Select your sorting preference, sorting as many fields as desired. Select your sort order by adjusting the numbers in the Sort Order column. Quick Reference Guide STI_1106071235 STIDistrict Query (Basic) 4
Setting Grouping Options To set grouping options: Select the fields to query and click the button. Locate the field you wish to group. Follow the row across to the Group By column. Set your grouping options accordingly. Examples may be found in the section Aggregate Functions on page 10. Note: A very common reason for grouping records is make a count of how many records exist within each group. The example below shows a count of student records within a grouping by Grade and by Gender. Notice that the Alias column has the word Count in it, on the Student Number row. The Alias field MUST be completed for rows that contain counts. This field must also be completed for any of the grouping functions Quick Reference Guide STI_1106071235 STIDistrict Query (Basic) 5
Linking Views and/or Tables When using more than one view or table within a query, the views and/or tables will need to be linked together. Perform the following steps to do this: Locate the tables you wish to query. Find a common field between the two tables, such as Student_Number. (The STIDistrict Query (Advanced) document has examples of common joins.) Highlight the field on one of the tables. Drag and drop the field from one table to the other. Repeat these steps for any other joins to be made between the two tables. Double-click on the link between the two tables and set Join Properties accordingly. For example, if you are creating a query that uses both the Student_Demographics and Student_Attendance views, and you wish to list all students in the query even if they have no absence records in the database, you would double-click on each of the join lines between the two views and select Include all rows from qrystudent_demographics before clicking Accept. Quick Reference Guide STI_1106071235 STIDistrict Query (Basic) 6
Saving a Query To save an existing query: Click the button. Enter all desired information and click OK. o o o o o Name: Enter a name to use to identify the query. Category: Select a category from the drop-down list in which to save the query. Description: Enter a good description of what the query does. Locked: Select this option to prevent other users (who belong to other user security groups) from opening and altering the query. Private: Select this option to prevent other users (who belong to other user security groups) from opening the query at all. Opening a Saved Query To open a saved query through the STIDistrict Query Builder: Click the button. Name the query and select the category in which to save the query. (You may create new categories from within STIDistrict Workstation, under Utilities Query List.) Enter a description of the query. This description will be displayed in the header portion of the printed query. The description is therefore a useful way to communicate to the recipient of the query data exactly what sort of information the data represents. Suggested content of this area might include the user who developed the query, the criteria for data within the query, and any other information that may be helpful. Select Locked to deny anyone who does not belong to your user security group the ability to open and modify the query. Select Private to deny anyone who does not belong to your user security group the ability to open the query. Quick Reference Guide STI_1106071235 STIDistrict Query (Basic) 7
Printing and Exporting Query Results Query results may be printed or exported using the following buttons on the toolbar: Click on the Print Results button to send the data to a printer for a hard copy. In this process, the results are first displayed in a formatted report style. Click on the Print button to print these results, or click on the X (Close) button to close the report. When a report is closed, an option to export the data to a file will be presented. Select the file format in which to save the report, if desired. Note that the saved data will retain the formatting of the report. Click on the Export Results button to export the data to a file. File formats available are ASCII, HTML, and XML. Exporting data in this way saves data in columns, with no formatting. Click on the Microsoft Word button to launch the wizard to merge query results into a Word document. Click on the Microsoft Excel button to launch the wizard to merge query results into an Excel Spreadsheet. Query List To open the Query List in STIDistrict Workstation, select Utilities Query List. Queries that have been created and saved using the Query Tool will be available under this menu option. When a query is selected from the menu, the data is refreshed against the current data in the database. To print the query results, simply select the query from the list and then click the Run Query button. To edit the query, click on the Edit Query button. Quick Reference Guide STI_1106071235 STIDistrict Query (Basic) 8
Comparison Operators The following list of operators may be used for defining criteria for the data in the query. These operators would be entered into the Criteria column, with criteria as shown in the examples below. Operator Meaning = (Equal) Equal to > (Greater Than) Greater than < (Less Than) Less than >= (Greater Than or Equal To) Greater than or equal to <= (Less Than or Equal To) Less than or equal to <> (Not Equal To) Not equal to!> Not Greater Than (This is equivalent to <=)!< Not Less Than (This is equivalent to =>)!= Not Equal To (This is equivalent to =) Between BETWEEN x AND y, Inclusive selection between the supplied criteria. Comparison Operator Examples If you are trying to locate records for all students who ride bus #45, you would add the BUS_1 field to the grid and in the criteria column you would enter: =45 For students who ride on buses #45 - #50, you would add the BUS_1 field to the grid and in the criteria column for the BUS_1, you would enter: Between 45 and 50 The result of a comparison operator has the Boolean data type, which has three values: True, False and Unknown. Expressions with Boolean data types are used in the WHERE clause to filter the rows that qualify for the search conditions. Quick Reference Guide STI_1106071235 STIDistrict Query (Basic) 9
Logical Operators Logical operators test for the truth of some condition. Logical operators, like comparison operators, return a Boolean data type with a value of True or False. Operator IN LIKE NOT Meaning IN allows you to create a list of criteria (for example you would enter IN (15, 46, 99) if you were trying to find students on buses 15,46,99. LIKE is used for pattern matching. Normally it is used with the % wildcard. To use LIKE on the LNAME field you would enter LIKE MILL%, the result would return any records where the Last Name started with MILL (MILL,MILLS,MILLER) NOT Reverses the value of any other Boolean operator. Using the LIKE example above NOT LIKE MILL%, the result would return any records where the LastName DOES NOT START with MILL. Aggregate Functions Aggregate functions will be available in Daisi workstation 4.08 and higher. Aggregate functions allow you the ability to get totals of like records. Operator GROUP BY SUM MIN MAX COUNT AVG MIN DISTINCT MAX DISTINCT COUNT DISTINCT Meaning Assigns fields that must be the same to do the aggregate function. This is known as the group Creates a total within the group Finds the lowest value in the aggregate group Finds the highest value in the aggregate group Count the total number in the group Averages the field within the group The lowest of unique input values The highest of unique input values The number of unique input values Quick Reference Guide STI_1106071235 STIDistrict Query (Basic) 10