EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 SQL Writing Style It's possible to write two queries that stylistically look different but that perform identically and yield identical results. In order to maximize efficiencies while creating and maintaining queries, we recommend that you choose a consistent SQL writing style. However, you need to be able to interpret and potentially modify SQL queries that were not created by you: either created by somebody else or by an automated process. Therefore, you need to be comfortable with all common SQL writing styles. Column Aliases Column aliasing allows you to assign names to the columns in your query result. One benefit of aliasing columns is that the column heading is modified, potentially making the column values easier to interpret. Other benefits will be introduced later in this training companion. Column aliases are defined in the SELECT clause. There are many syntaxes for defining aliases, and several are version dependent. You can use the AS keyword in a column alias to make it explicit, but it is not required If the column alias has a space in it, it must be enclosed in double quotes ﴾SQL Server also allows [square brackets] and 'single quotes'﴿ /* A query demonstrating different styles of aliasing columns */ SELECT GuarantorEpicID AS ID, Name "Guarantor Name", BirthDate DOB FROM GuarantorDim You've seen that column aliases are defined in the SELECT clause and recall that the SELECT clause is processed before the ORDER BY clause. That means you can use aliases in the ORDER BY clause. /* A query demonstrating a column alias used in the ORDER BY clause */ SELECT GuarantorEpicID "ID", Name "Guarantor Name", BirthDate "DOB" FROM GuarantorDim ORDER BY "DOB" General Style Choices Consider the following SQL query: Write a Basic Query 3 • 14 RPT101i SQL I 51
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 SELECT PAT_ID "Patient ID", PAT_NAME "Patient Name", PAT_MRN_ID "Patient MRN", AGE_YEARS "Age in Years", CUR_PCP_NAME "Primary Care Provider" FROM V_PAT_FACT There are several stylistic choices that have been made here, the first of which is to make the code atomic. This means that each individual piece of code is placed on its own line. In atomic code, it is easier to see what is happening within different sections of code and to comment out single lines. SQL ignores whitespace, so adding spaces and carriage returns makes the code more readable while maintaining functionality. Also notice that the keywords ﴾ SELECT and FROM ﴿ are in CAPITAL LETTERS, database object and column names are cased consistently, and the alias styling is consistent. These style choices have no actual effect on the SQL query or the results. The following code would return the same results: Select pat_id as "Patient ID", PAT_name "Patient Name",pat_MRN_ID "Patient MRN",AGE_yea rs "Age in Years",CUR_PCP_NAME "Primary Care Provider" from v_pat_fact Exercise 7: Add Column Aliases In this exercise, you'll practice adding column aliases to an existing query. Task Write a query to return the PROV_ID, PROV_NAME, PROV_TYPE, STAFF_RESOURCE_C, and EXTERNAL_NAME columns from the CLARITY_SER table ﴾using your solution from Exercise 2: SELECT Columns﴿. Use the following aliases for the columns, respectively: Provider ID, Provider Name, Provider Type, Person or Thing, Printed Name. Step‐by‐Step 1. Open the query you created in Exercise 2: SELECT Columns. 2. Modify the SELECT clause by adding the column aliases as indicated in the exercise summary above. For example, the first column in your SELECT clause should look like this: PROV_ID "Provider ID" 3. Add spacing between your column names and column aliases to make your query easier to read. Exercise 8: SELECT Columns with Aliases In this exercise, you'll practice including column aliases in a new query. 3 • 15 Write a Basic Query 52 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Background The HospitalAdmissionFact table has one row per hospital admission encounter Task Create and run a query to return the PatientKey, AdmittingProviderKey, DischargingProviderKey, DepartmentKey, AdmissionDateKey, DischargeDateKey, and LengthOfStayInDays columns from the HospitalAdmissionFact table. Use the following aliases for the columns, respectively: Patient Key, Admission Provider, Discharge Provider, Department, Admission Date, Discharge Date, and Length of Stay. Write a Basic Query 3 • 16 RPT101i SQL I 53
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Reviewing the Chapter Review Questions 1. Which clause in a SELECT statement is evaluated first? 2. Which clause in a SELECT statement is evaluated last? 3. True or False: Comments must be on their own line of the query. 4. What is the syntax for a block ﴾multi‐line﴿ comment? 5. What technique can be used to rename columns in a SQL query? 6. What keyword can you use to change the direction of a sort in SQL? Review Key 3 • 17 Write a Basic Query 54 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Review Key 1. Which clause in a SELECT statement is evaluated first? FROM 2. Which clause in a SELECT statement is evaluated last? ORDER BY 3. True or False: Comments must be on their own line of the query. False 4. What is the syntax for a block ﴾multi‐line﴿ comment? /* Comment goes here */ 5. What technique can be used to rename columns in a SQL query? Aliasing 6. What keyword can you use to change the direction of a sort in SQL? DESC Study Checklist Write a Basic Query 3 • 18 RPT101i SQL I 55
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Study Checklist Make sure you can define the following key terms: ☐ SELECT statement ☐ SELECT clause ☐ FROM clause ☐ Column alias ☐ ORDER BY clause ☐ DESC keyword Make sure you can perform the following tasks: ☐ List all of the rows and columns in a table ☐ Add comments to a SQL query ☐ Add a line comment to a SQL query ☐ Add a block comment to a SQL query ☐ List data from specific columns in a table ☐ Use column aliases in a SQL query ☐ Sort the results of a SQL query Make sure you fully understand and can explain the following concepts: ☐ SQL is a declarative programming language ☐ The clauses in a SELECT statement are processed in an order different than the order in which they appear ☐ The FROM clause is processed first ☐ The ORDER BY clause is processed after the SELECT clause ☐ The result of a SELECT statement is a table ☐ Why it is important to add comments to a SQL query ☐ Why it is important to be able to interpret SQL queries that use different SQL writing styles ☐ Whitespace doesn't affect the processing of the SELECT statement 3 • 19 Write a Basic Query 56 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 ☐ Capitalization doesn't affect the processing of the SELECT statement Write a Basic Query 3 • 20 RPT101i SQL I 57
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Logical Expressions Introduction Logical Expression Processing Example Rules of Logical Expressions Three‐Value Logic Finding Nulls Negating Expressions Exercise 1: Evaluate Logical Expressions Apply Logical Expressions The CASE Statement Exercise 2: CASE with Date/Time Exercise 3: CASE with NULL Exercise 4: CASE with Multiple Columns Exercise 5: CASE with Multiple Conditions The WHERE Clause Exercise 6: IS NULL Condition Exercise 7: WHERE with Numeric Exercise 8: WHERE with NULL Exercise 9: WHERE with Character String Exercise 10: No Column Aliases in WHERE Use Multiple Conditions AND: Both OR: One or the Other or Both Exercise 11: Combine Criteria with AND Exercise 12: Combine Criteria with OR Exercise 13: WHERE with NULL or Character String 4 • 4 4 • 5 4 • 6 4 • 8 4 • 9 4 • 9 4 • 10 4 • 16 4 • 16 4 • 17 4 • 18 4 • 18 4 • 19 4 • 19 4 • 20 4 • 21 4 • 22 4 • 22 4 • 22 4 • 24 4 • 25 4 • 25 4 • 25 4 • 26 4 • 27 4 • 1 Logical Expressions 58 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Summary of Three‐Value Logic Exercise 14: Combine Criteria with NOT Precision and Scale Exercise 15: WHERE with Date Range Exercise 16: WHERE with Date Range and Character String Granularity Exercise 17: WHERE to Reduce Granularity The ROWNUM Pseudocolumn ﴾Oracle﴿ Reviewing the Chapter 4 • 27 4 • 28 4 • 29 4 • 31 4 • 31 4 • 31 4 • 33 4 • 34 4 • 35 Logical Expressions 4 • 2 RPT101i SQL I 59
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 4 • 3 Logical Expressions 60 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Introduction Thus far we've been able to specify which columns to include in a query result. In this lesson, we'll specify which rows will be included in a query result. We'll also return columns with values derived from columns in the database. All of this is required for typical published queries and can be accomplished with logical expressions. The PAT_ENC table contains one row for each patient encounter, but what if you are only interested in office visits, or telephone encounters? What if you need the query to return only patients with a specific diagnosis in the last year, as opposed to a list of all patients? How can you list all hospital encounters yet make it easy to interpret whether the admitting provider and the discharge provider were the same person? By the End of This Lesson, You Will Be Able To... Create a column with values dependent on specified conditions Filter results based on one column's data Filter results based on multiple columns' data Logical Expressions 4 • 4 RPT101i SQL I 61
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Logical Expression Processing Example 4 • 5 Logical Expressions 62 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Rules of Logical Expressions The fundamental task in query writing is to ensure that all of the needed data and no unnecessary data is returned by the query. This is accomplished by using statements called logical expressions. Logical expressions: 1. Are made up of comparisons 2. Evaluate to TRUE, FALSE, or UNKNOWN 3. Can be combined with other expressions 4. Must evaluate to TRUE to satisfy a condition Logical expressions are made up of one or more values and an operator. The values can be constants or columns from the database. The most common form for logical expressions is the following: value1 operator value2 Here are a few examples of logical expressions: PatientDim.Name = 'Johnson,James' F_SCHED_APPT.APPT_DTTM >= '2016‐01‐24' BillingTransactionFact.Amount BETWEEN 1000 AND 9999.99 ORDER_MED.DISCON_TIME IS NULL Internally, date/time columns are stored as a number of units ﴾for example, days﴿ since a specific time far in the past. Therefore, as far as comparisons are concerned, date A is considered less than date B if date A occurred before date B. This example would return all rows for which F_SCHED_APPT.APPT_DTTM is 24 Jan 2016 or later. F_SCHED_APPT.APPT_DTTM >= '2016‐01‐24' String and date constants should be enclosed in single quotes. Logical Expressions 4 • 6 RPT101i SQL I 63
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 In SQL Server, there are many different date formats accepted, like '01/24/2016' , '1/24/201 6' , '24 JAN 2016' , and 'Jan 24, 2016' . In Oracle, a string in the format 'DD MON YYYY' can be interpreted as a date or the date literal must be used to convert a string in 'YYYY‐MM‐ DD' format to a date. F_SCHED_APPT.APPT_DTTM >= '24 JAN 2016' F_SCHED_APPT.APPT_DTTM >= date '2016‐01‐24' Other options for working with dates are given in the Functions lesson. The data types on both sides of the operator must match or be such that the server can automatically convert from one to the other. SQL may not know whether 'April 20, 1984' is larger than the number 4011980, nor can it tell if the word 'Fifteen' equals the number 15. Below are many types of comparison operators you may see in logical expressions. Two‐Value Comparisons Description value1 = value2 Equal value1 <> value2 Not equal value1 < value2 Less than value1 <= value2 Less than or equal value1 > value2 Greater than value1 >= value2 Greater than or equal 4 • 7 Logical Expressions 64 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Complex Comparisons Description value1 BETWEEN value2 AND value3 Greater than or equal to value2 and less than or equal to value3 value1 NOT BETWEEN value2 AND value3 Less than value2 or greater than value3 value1 IN (value2, value3, ...) Equal to one of several values value1 NOT IN (value2, value3, ...) Not equal to any of several values value LIKE pattern Matches a pattern. The pattern can include an underscore " _ " meaning "any character" and a percent sign " % " meaning "any string of characters" value NOT LIKE pattern Does not match a pattern. Null Checks Description value IS NULL Null value check value IS NOT NULL Non‐null value check Three‐Value Logic SQL uses a logical system known as three‐value logic: all logical expressions evaluate to TRUE, FALSE, or UNKNOWN. You may be familiar with the first two, but it is important to account for the possibility of UNKNOWN. Consider the following expression: PatientDim.City = 'Verona' This expression means "The patient lives in Verona." For a patient who lives in Verona, this statement would be TRUE. For a patient who lives somewhere other than Verona, this statement would be FALSE. However, some patients have NULL in CITY. You don't know if these patients live or don't live in Verona. There isn't enough data to say for sure. When there is insufficient data to make the comparison, the statement evaluates to UNKNOWN. Logical Expressions 4 • 8 RPT101i SQL I 65
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Here are some examples from earlier: PatientDim.Name = 'Johnson,James' This statement will be TRUE for any patient named 'Johnson,James', FALSE for any patient with a different name, and UNKNOWN for any patient with NULL in the PAT_NAME column. F_SCHED_APPT.APPT_DTTM >= '2016‐01‐24' This statement will be TRUE for any encounter on or after January 24th, 2016, FALSE for any encounter earlier than January 24th, 2016, and UNKNOWN for any encounter with NULL in APPT_DTTM. BillingTransactionFact.Amount BETWEEN 1000 AND 9999.99 This statement will be TRUE for any transaction between $1000 and $9999.99, FALSE for any transaction outside of that range, and UNKNOWN for any transaction with NULL in TX_AMOUNT. Finding Nulls NULL is never equal to anything, even itself. When NULL appears in a comparison, there isn't enough data to compute the expression. Consider the following expression: PATIENT.CITY = NULL This expression is never TRUE and never FALSE; it is always UNKNOWN. To find NULL values, the following expression would be appropriate: PATIENT.CITY IS NULL The IS operator is used to check if a value is NULL . The expression value IS NULL will always evaluate to TRUE for NULL values and FALSE for populated values. This expression cannot be UNKNOWN. Here's another example from earlier: ORDER_MED.DISCON_TIME IS NULL This expression will be TRUE for any order without a value for discontinued time and FALSE for any order with a value for discontinued time. This expression can never be UNKNOWN. Negating Expressions 4 • 9 Logical Expressions 66 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 When working with logical expressions, the keyword NOT can be added to reverse TRUE and FALSE statements. To reverse an entire logical expression, NOT should be placed immediately before the logical expression. This is also how to reverse a two‐value comparison To reverse a complex comparison, NOT can alternatively be placed immediately before the original keyword To reverse IS NULL use IS NOT NULL . ‐‐These are three valid comparisons NOT CONTACT_DATE >= '1 JAN 2000' NOT PAT_NAME LIKE '%Carina%' PAT_NAME NOT LIKE '%Carina%' ‐‐This is not a valid comparison CONTACT_DATE NOT >= '1 JAN 2000' However, UNKNOWN differs from FALSE in that the statement NOT FALSE evaluates to TRUE, while the statement NOT UNKNOWN evaluates to UNKNOWN. Consider this expression from an earlier example: NOT PatientDim.City = 'Verona' For the patients who live in Verona, this expression is now FALSE. For patients who live in a city other than Verona, this statement is now TRUE. But for patients with a NULL city, this expression is still UNKNOWN. If the patient has no documented city, you don't know if the patient lives in Verona. You also don't know if the patient does NOT live in Verona. Exercise 1: Evaluate Logical Expressions In this exercise, you'll practice evaluating logical expressions by hand. Consider the following set of patients. Then, for each logical expression below, mark TRUE, FALSE, or UNKNOWN for each patient. Logical Expressions 4 • 10 RPT101i SQL I 67
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 PAT_ID PAT_NAME BIRTH_DATE ZIP PAT_STATUS_C Z1 THIRA, LAURA 17 MAR 1987 53719 1 Z2 ZARVEN, BRIAN 22 JAN 1985 48160 1 Z3 CORWIN, ANDY 17 MAY 1990 53720 NULL Z4 KARA, CONNIE 11 JUL 1986 48104 2 Z5 NULL NULL 53719 NULL For example, for the expression PAT_ID = 'Z2' PAT_ID TRUE, FALSE, OR UNKNOWN? Z1 FALSE Z2 TRUE Z3 FALSE Z4 FALSE Z5 FALSE Part 1: Not Equal PAT_ID <> 'Z3' 4 • 11 Logical Expressions 68 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 PAT_ID TRUE, FALSE, OR UNKNOWN? Z1 TRUE Z2 TRUE Z3 FALSE Z4 TRUE Z5 TRUE Part 2: Less Than Date BIRTH_DATE < '01 JAN 1990' PAT_ID BIRTH_DATE TRUE, FALSE, OR UNKNOWN? Z1 17 MAR 1987 TRUE Z2 22 JAN 1985 TRUE Z3 17 MAY 1990 FALSE Z4 11 JUL 1986 TRUE Z5 NULL UNKNOWN Part 3: BETWEEN Dates BIRTH_DATE BETWEEN '22 JAN 1985' AND '17 MAR 1987' Logical Expressions 4 • 12 RPT101i SQL I 69
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 PAT_ID BIRTH_DATE TRUE, FALSE, OR UNKNOWN? Z1 17 MAR 1987 TRUE Z2 22 JAN 1985 TRUE Z3 17 MAY 1990 FALSE Z4 11 JUL 1986 TRUE Z5 NULL UNKNOWN Part 4: IN ZIP IN ('53593', '53711', '53719') PAT_ID ZIP TRUE, FALSE, OR UNKNOWN? Z1 53719 TRUE Z2 48160 FALSE Z3 53720 FALSE Z4 48104 FALSE Z5 53719 TRUE Part 5: LIKE Any Character ZIP LIKE '537__' ‐‐ 2 underscores 4 • 13 Logical Expressions 70 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 PAT_ID ZIP TRUE, FALSE, OR UNKNOWN? Z1 53719 TRUE Z2 48160 FALSE Z3 53720 TRUE Z4 48104 FALSE Z5 53719 TRUE Part 6: LIKE Any Characters PAT_NAME LIKE '%, ANDY' PAT_ID PAT_NAME TRUE, FALSE, OR UNKNOWN? Z1 THIRA, LAURA FALSE Z2 ZARVEN, BRIAN FALSE Z3 CORWIN, ANDY TRUE Z4 KARA, CONNIE FALSE Z5 NULL UNKNOWN Part 7: IS NULL PAT_STATUS_C IS NULL Logical Expressions 4 • 14 RPT101i SQL I 71
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 PAT_ID PAT_STATUS_C TRUE, FALSE, OR UNKNOWN? Z1 1 FALSE Z2 1 FALSE Z3 NULL TRUE Z4 2 FALSE Z5 NULL TRUE 4 • 15 Logical Expressions 72 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Apply Logical Expressions There are several places you can find logical expressions in a SQL query. In this lesson, you'll see two: CAS E statements and the WHERE clause. The CASE Statement The CASE statement allows you to use logical expressions to determine which values to return in your results. There are two formats for a CASE statement. The first involves choosing each value based on a separate logical expression. CASE WHEN logical_expression1 THEN value1 WHEN logical_expression2 THEN value2 /* ... */ ELSE default_value END The CASE statement will return the value associated with the first TRUE logical_expression . Note the EN D , which is required with all CASE statements. When the CASE statement is in the SELECT clause, by default the resulting column will not have a column name. More broadly, anything more complex than a single‐column reference in the SELECT clause will not have a column name in the result. Using a nameless column within a query or in a reporting tool may be difficult if not impossible. Therefore, it is recommended to use column aliases to ensure that every column in the result has a name. For CASE statements in the SELECT clause, this is done following the END keyword. You are writing a query on encounters and want to identify encounters that patients had with their general primary care providers. The PAT_ENC table has one row per patient encounter, a column indicating this visit provider ﴾VISIT_PROV_ID﴿, and a column indicating their general PCP at the time of the encounter ﴾PCP_PROV_ID﴿. So, you can use a CASE statement to identify the requested encounters: SELECT PAT_ENC_CSN_ID, CONTACT_DATE, VISIT_PROV_ID, PCP_PROV_ID, CASE WHEN VISIT_PROV_ID = PCP_PROV_ID THEN 'Visit with PCP' WHEN VISIT_PROV_ID <> PCP_PROV_ID THEN 'Visit with other provider' ELSE 'Missing Data' END "With PCP" FROM PAT_ENC Logical Expressions 4 • 16 RPT101i SQL I 73
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 The second format of the CASE statement limits you to comparing values against only a single value. The implicit operator for the comparison is =. CASE value0 WHEN value1a THEN value1b WHEN value2a THEN value2b /* ... */ ELSE default_value END For example, the CLARITY_SER table has one row per provider and the IS_RESIDENT column indicates if the provider is a resident. The following two queries accomplish the same task of converting the IS_RESIDENT column in the CLARITY_SER table into a friendlier format. SELECT PROV_ID, IS_RESIDENT, CASE WHEN IS_RESIDENT = 'Y' THEN 'Yes' WHEN IS_RESIDENT = 'N' THEN 'No' ELSE 'Unknown' END "Resident" FROM CLARITY_SER Using the second format, the above statement can also be written like this: SELECT PROV_ID, IS_RESIDENT, CASE IS_RESIDENT WHEN 'Y' THEN 'Yes' WHEN 'N' THEN 'No' ELSE 'Unknown' END "Resident" FROM CLARITY_SER Temporarily adding extra columns to the SELECT clause can help you troubleshoot and validate the SELECT statement. In particular, to check if a CASE statement is behaving as desired, add the columns used by the CASE statement to the SELECT clause. Run your modified query and compare the values returned by the CASE statement with the columns you just added. For example, in the previous example the IS_RESIDENT and "Resident" columns return similar information. Therefore, it is likely that only one of the columns ﴾probably the "Resident" column created by the CASE statement﴿ is needed in a final query. However, leaving the IS_RESIDENT column in the SELECT clause while developing your query can help you verify that the "Resident" column is returning the appropriate values. Exercise 2: CASE with Date/Time 4 • 17 Logical Expressions 74 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 In this exercise, you'll practice using the CASE statement to add meaning to a date/time column. Background The PATIENT table has one row per patient The PAT_ID column holds the patient's ID The PAT_NAME column holds the patient's name The CITY column holds the patient's city The BIRTH_DATE column holds the patient's birth date Task For this and similar exercises in this lesson, it's ok to hard code a date into your queries. The Functions lesson covers how to make your queries more dynamic and easier to maintain. Write a query to return patient IDs, patient names, patient cities, and patient birth dates. Then add a result column aliased "Demographic" to return whether each patient is an 'Adult Patient', 'Pediatric Patient', or of an 'Unknown Age'. For the purposes of this exercise, a pediatric patient is someone whose birth date is equal to or later than today's date 18 years ago. Exercise 3: CASE with NULL In this exercise, you'll practice using the CASE statement to add meaning to a nullable column. Background The RX_MED_TWO table has one row per medication The MEDICATION_ID column holds the medication's ID The MEDICATION_NAME column holds the medication's name The RX_TEMPLT_TYP_NAME column is populated if and only if the medication is a mixture Task Write a query to list medications. Return the medication ID and the medication name. Then add a result column aliased "Mixture" with a "Yes" or "No" that indicates if the medication is a mixture. Exercise 4: CASE with Multiple Columns In this exercise, you'll practice using a CASE statement that involves multiple columns. Background The PATIENT table has one row per patient The PAT_ID column holds the patient's ID The PAT_NAME column holds the patient's name Logical Expressions 4 • 18 RPT101i SQL I 75
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 The WORK_PHONE column holds the patient's work phone number The HOME_PHONE column holds the patient's home phone number Task Write a query to return patient IDs and patient names. Then add a result column aliased "Phone" to return one phone number for each patient. The work phone number is preferred over the home phone number. If the patient has neither phone number, return the text 'No phone listed'. Save your query so you can build on it in Exercise 10: No Column Aliases in WHERE. Exercise 5: CASE with Multiple Conditions In this exercise, you'll practice using a CASE statement that involves multiple conditions. Background The ARPB_TRANSACTIONS table has one row per professional billing transaction The TX_ID column holds the transaction ID The OUTSTANDING_AMT column holds the outstanding amount The POST_DATE column holds the post date Task Write a query on professional billing transactions. Return the transaction ID, the outstanding amount, and the post date. Then add a result column aliased "Aging Bucket": If the outstanding amount is 0, this column should return 'N/A' Otherwise, if the post date was 30 days ago or more recent, this column should return '0‐30'. Otherwise, if the post date was 31‐60 days ago, return '31‐60'. Otherwise, if the post date was older than 60 days ago, return 'more than 60.' For this exercise, you may hard code the dates instead of using functions, covered in the Functions lesson. The WHERE Clause The WHERE clause filters rows from your results. The WHERE clause holds one logical expression. You use the logical expression to describe which rows should be returned in your results. Review The SELECT Statement section of the Write a Basic Query lesson as a reminder of where the WHERE clause appears and when it is processed in relation to the other clauses. Your WHERE clause is evaluated for each row of the included tables, and its logical expression must evaluate to TRUE for a row in order for that row to appear in your results. If the expression evaluates to FALSE or UNKNOWN, the data will be excluded from your results. 4 • 19 Logical Expressions 76 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Imagine you wanted to only find patients that lived in Verona. You could use this query: SELECT * FROM PATIENT WHERE CITY = 'Verona' Instead of returning all patients, this returns only patients that live in Verona. Patients who live elsewhere, and patients with a NULL city, will be excluded. Recall that temporarily adding extra columns to the SELECT clause can help you troubleshoot and validate the SELECT statement. In particular, to check if a WHERE clause is behaving as desired, add the columns used by the WHERE clause to the SELECT clause. Run your modified query and verify that the values of the columns you just added match what you expect based on the filtering performed by the WHERE clause. For example, imagine you wanted to find the names of the patients that live in Verona. You could use this query: SELECT PAT_NAME FROM PATIENT WHERE CITY = 'Verona' Suppose you are unsure if the string comparison in the WHERE clause is case sensitive: if the CITY column has a value of 'VERONA' then will the patient's name still be returned? This can easily be verified by temporarily adding the CITY column to the SELECT clause, running the query, and browsing the results. SELECT PAT_NAME, CITY ‐‐ Temporary addition FROM PATIENT WHERE CITY = 'Verona' Exercise 6: IS NULL Condition In this exercise, you'll compare some correct and incorrect ways of testing for NULL values to reinforce the usefulness of the IS operator. 1. Run the following query. SELECT * FROM PATIENT WHERE CUR_PCP_PROV_ID = NULL 2. How many results did you get? Logical Expressions 4 • 20 RPT101i SQL I 77
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Zero 3. Run the following query. SELECT * FROM PATIENT WHERE NOT (CUR_PCP_PROV_ID = NULL) 4. How many results did you get? Zero 5. Run the following query. SELECT * FROM PATIENT WHERE CUR_PCP_PROV_ID IS NULL 6. How many results did you get? Answers vary depending on when and in which database the query is run 7. Run the following query. SELECT * FROM PATIENT WHERE NOT (CUR_PCP_PROV_ID IS NULL) 8. How many results did you get? Answers vary depending on when and in which database the query was run 9. In SQL, can you use an equal sign ﴾=﴿ to find null values? Why did you get the same number of results in the first two queries? No, you should use the IS operator instead. If you use = , the result will always be UNKNOWN, and NOT UNKNOWN is still UNKNOWN. UNKNOWN results are excluded by the WHERE clause. Exercise 7: WHERE with Numeric In this exercise, you'll practice using a WHERE clause with numeric values. Background The BillingAccountFact table has one row per billing account The HasOpenDenial column indicates whether there is an open denial on the account A value of 1 indicates an open denial 4 • 21 Logical Expressions 78 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 The AccountEpicID column holds the account ID The ActiveArBalance column holds the amount the organization is actively collecting Task Write a query that returns the ID and active balance on all hospital accounts with an open denial. Exercise 8: WHERE with NULL In this exercise, you'll practice using a WHERE clause that filters out NULL s. Background The ACCOUNT table has one row per guarantor account The HB_BALANCE column holds the Hospital Billing balance The ACCOUNT_ID column holds the account ID The ACCOUNT_NAME column holds the account name Task Find all guarantor accounts with a Hospital Billing balance ﴾including a zero balance﴿. Return the Hospital Billing balance, the account ID, and the account name. Exercise 9: WHERE with Character String In this exercise, you'll practice using a WHERE clause with character string values. Background The CLARITY_TBL table has one row per Clarity table The DEPRECATED_YN column indicates whether or not the table has been deprecated A value of 'Y' indicates that the table has been deprecated The TABLE_NAME column holds the table name The TABLE_ID column holds the table ID The TABLE_INTRODUCTION column holds the table description Task Create a list of all the tables in Clarity that have been deprecated. Return the table name, table ID, and table description. Exercise 10: No Column Aliases in WHERE In this exercise, you'll learn why the WHERE can't reference column aliases and what you can do instead. Task Start with your solution to Exercise 4: CASE with Multiple Columns. You've been asked to modify the query to exclude patients with a phone number including the text "‐555‐". Attempt to do so by filtering on the Logical Expressions 4 • 22 RPT101i SQL I 79
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 "Phone" column alias. Result What error message do you receive? Invalid column name 'Phone'. This is a result of the fact that the WHERE clause is evaluated before the SELECT clause: when the database processes the WHERE clause, it hasn't yet processed the definition of "Phone" so it can't filter on that column. Column aliases established in the SELECT clause cannot be used in clauses that are processed before the SELECT clause. While perhaps inconvenient, there is a workaround: copy the definition of the aliased column from the SELECT clause and paste it into the other clause where you would have liked to use the alias. In this case, you can copy "CASE...END" to replace ""Phone"" in the WHERE clause. Follow‐Up Task Fix your query to perform as requested without attempting to use the column alias in the WHERE clause. This is the end of the exercise. 4 • 23 Logical Expressions 80 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Temporarily adding extra conditions to the WHERE clause can help you troubleshoot and validate the rest of your SELECT statement. In particular, to check if a CASE statement is behaving as desired, add one or more of the conditions used by the CASE statement to the WHERE clause. Run your modified query and verify that the values of the columns match what you expect based on the filtering performed by the WHERE clause. In a previous example, this query returned one row per provider and indicated whether or not the provider is a resident. SELECT PROV_ID, IS_RESIDENT, CASE IS_RESIDENT WHEN 'Y' THEN 'Yes' WHEN 'N' THEN 'No' ELSE 'Unknown' END "Resident" FROM CLARITY_SER After running the query, you may notice that a lot of 'No' and 'Unknown' values are returned ﴾because relatively few providers are marked as residents﴿. How can you tell if the 'Yes' portion of the CASE statement is performing as selected? Temporarily add a WHERE clause that only returns rows where IS_RESIDENT = 'Y'! Run the query, look at the results, and verify that your CASE statement is returning 'Yes' appropriately. SELECT PROV_ID, IS_RESIDENT, CASE IS_RESIDENT WHEN 'Y' THEN 'Yes' WHEN 'N' THEN 'No' ELSE 'Unknown' END "Resident" FROM CLARITY_SER WHERE IS_RESIDENT = 'Y' ‐‐ Temporary test Use Multiple Conditions It is possible to combine logical expressions with logical operators ﴾ AND , OR , and NOT ﴿ to make a more complex logical expression. When using a mix of logical operators, use parentheses to override the order of operations and to make the query more readable. The innermost parentheses are evaluated first. Without parentheses, NOT is evaluated first, then AND , then OR . A common mistake is to try to combine multiple values using logical operators, for example PATIENT.SEX_C = '1' OR '2' . This is not correct. Logical operators can only be used to combine whole logical expressions. The correct syntax here would be PATIENT.SEX_C = '1' O R PATIENT.SEX_C = '2' . Logical Expressions 4 • 24 RPT101i SQL I 81
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 AND: Both When a query needs multiple filters to be respected simultaneously, the AND operator may be used. Rows will only be returned from the query if the statements on both sides of AND evaluate to TRUE for that record. /* A query that returns all males born before 1984 */ SELECT PAT_ID, PAT_NAME FROM PATIENT ‐‐Patient is Male WHERE SEX_C = '2' ‐‐Patient was born before 1984 AND BIRTH_DATE < '01 JAN 1984' If both pieces of an AND expression are TRUE, then the result of the AND is TRUE. If either piece is FALSE, then the expression is FALSE. TRUE AND UNKNOWN, as well as UNKNOWN AND UNKNOWN, will both evaluate to UNKNOWN. OR: One or the Other or Both When a query needs at least one filter among a set to be respected, the OR operator may be used. Rows will be returned from the query so long as one or more of the individual filters evaluate to TRUE. The VisitFact table has one row per face‐to‐face patient encounter. The Closed column indicates if the encounter is closed NULL means the encounter is not yet open and can't yet be closed 0 means the encounter is open 1 means the encounter is closed You've been asked to write a query of patient encounters that are not closed. SELECT PatientKey, EncounterDateKey, MinutesInRoom FROM VisitFact ‐‐Not yet open WHERE Closed IS NULL ‐‐Open OR Closed = 0 Exercise 11: Combine Criteria with AND In this exercise, you'll practice manually evaluating two conditions combined using AND . 4 • 25 Logical Expressions 82 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Imagine you've written the following query: SELECT * FROM PatientDim WHERE Sex = 'Male' AND BirthDate < '01 JAN 1984' Consider patients with different combinations of sexes and birth dates. Fill out the table below with a 'Yes' if the patient will be included in the results of the above query or an 'No' if the patient will not be included. AND Male Female NULL 10 OCT 1983 Yes No No 15 FEB 1987 No No No NULL No No No Exercise 12: Combine Criteria with OR In this exercise, you'll practice manually evaluating two conditions combined using OR . You've changed your query from Exercise 11: Combine Criteria with AND to read as follows: SELECT * FROM PatientDim WHERE Sex = 'Male' OR BirthDate < '01 JAN 1984' Fill out the table below with a 'Yes' if the patient will be included in the results of the above query or an 'No' if the patient will not be included, remembering the difference between AND and OR logic. Logical Expressions 4 • 26 RPT101i SQL I 83
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 OR Male Female NULL 10 OCT 1983 Yes Yes Yes 15 FEB 1987 Yes No No NULL Yes No No Exercise 13: WHERE with NULL or Character String In this exercise, you'll practice combining criteria, filtering on NULL values, and filtering on character strings. Background The CLARITY_SER table has one row per provider/resource The SEX_C column holds the sex of the provider/resource A value of '2' indicates 'Male' Task Write a query that lists non‐male ﴾no sex documented or not male﴿ providers/resources. Return all columns. Summary of Three‐Value Logic A B A AND B A OR B TRUE TRUE TRUE TRUE TRUE FALSE FALSE TRUE TRUE UNKNOWN UNKNOWN TRUE FALSE FALSE FALSE FALSE FALSE UNKNOWN FALSE UNKNOWN UNKNOWN UNKNOWN UNKNOWN UNKNOWN 4 • 27 Logical Expressions 84 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 A NOT A TRUE FALSE FALSE TRUE UNKNOWN UNKNOWN A Is A satisfied? TRUE Yes FALSE No UNKNOWN No Exercise 14: Combine Criteria with NOT Recall that NOT UNKNOWN is still UNKNOWN. With that in mind, imagine you've written the following query: SELECT * FROM PATIENT ‐‐2=Male WHERE NOT ( SEX_C = '2' AND BIRTH_DATE < '10 JAN 1984' ) Fill out the table below with a 'Yes' or 'No' for whether a patient would be included in these results. NOT ﴾...AND...﴿ Male ﴾2﴿ Female ﴾1﴿ NULL 10 OCT 1983 No Yes No 15 FEB 1987 Yes Yes Yes NULL No Yes No You've changed your query from before to read as follows: Logical Expressions 4 • 28 RPT101i SQL I 85
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 SELECT * FROM PATIENT ‐‐2=Male WHERE NOT ( SEX_C = '2' OR BIRTH_DATE < '10 JAN 1984' ) Fill out the table again, accounting for the difference between AND and OR logic. NOT ﴾...OR...﴿ Male ﴾2﴿ Female ﴾1﴿ NULL 10 OCT 1983 No No No 15 FEB 1987 No Yes No NULL No No No In this exercise you basically derived the following rules; you may find it convenient to refer back to their formal statements in the future: NOT ( A OR B ) = ( NOT A ) AND ( NOT B ) NOT ( A AND B ) = ( NOT A ) OR ( NOT B ) Precision and Scale When comparing two values, consider the possibility of one being more detailed than the other. If the two values being compared will always have the same level of detail, great! Then use the comparisons as you've learned thus far in this lesson. If the values may differ in detail, then choose your comparisons carefully. When comparing dates, "level of detail" means precision: is the date stored with a time? How precise is the time? To the hour? Minute? Second? Fraction of a second? Regardless of the precision, whatever is missing is considered to be zero. If there is no time at all, then the time is considered to be midnight ﴾12:00:00.000 AM﴿. 4 • 29 Logical Expressions 86 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 The PAT_ENC table has one row per patient encounter The CONTACT_DATE column holds the contact date; it does not hold a time If we need to return all contacts in the year 2017, then any of the following conditions in the WHERE clause would work: CONTACT_DATE BETWEEN '1 JAN 2017' AND '31 DEC 2017' '1 JAN 2017' <= CONTACT_DATE AND CONTACT_DATE <= '31 DEC 2017' '1 JAN 2017' <= CONTACT_DATE AND CONTACT_DATE < '1 JAN 2018' The PATIENT_2 table has one row per patient The BIRTH_TM column holds the date and time of the patient's birth to the nearest minute If we need to return all patients born in the year 2017, then any of the following conditions in the WHERE clause would work: BIRTH_TM BETWEEN '1 JAN 2017' AND '31 DEC 2017 23:59' '1 JAN 2017' <= BIRTH_TM AND BIRTH_TM <= '31 DEC 2017 23:59' '1 JAN 2017' <= BIRTH_TM AND BIRTH_TM < '1 JAN 2018' Notice in the examples above that the " <= AND < " solution is formatted similarly regardless of the precision of the date/time column: no times are listed, only dates are listed. For consistency and simplicity, consider adopting this method of comparing a date/time column with a range. When comparing numbers, "level of detail" means scale: how many digits are stored to the right of the decimal point? Again, regardless of the scale, whatever is missing is considered to be zero. Logical Expressions 4 • 30 RPT101i SQL I 87
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 The HSP_ACCOUNT table has one row per hospital account The TOT_ACCT_BAL column holds the current balance in dollars to the nearest cent If we need to return all hospital accounts with a balance of at least $100 but below $500, then any of the following conditions in the WHERE clause would work: TOT_ACCT_BAL BETWEEN 100 AND 499.99 100 <= TOT_ACCT_BAL AND TOT_ACCT_BAL <= 499.99 100 <= TOT_ACCT_BAL AND TOT_ACCT_BAL < 500 See the Functions lesson for additional solutions to working with values of varying levels of detail. Exercise 15: WHERE with Date Range In this exercise, you'll practice filtering on a date range. Background The OR_CASE table has one row per scheduled surgery The SURGERY_DATE column holds the date a surgery is/was scheduled to take place. Task Write a query to return a list of surgeries that were scheduled to take place in 2019. Exercise 16: WHERE with Date Range and Character String In this exercise, you'll practice combining criteria and filtering on a date range. Background The IP_FLWSHT_MEAS table has one row per documented flowsheet value The FLO_MEAS_ID column holds the ID of the type of flowsheet reading A value of '6' represents 'TEMPERATURE' The RECORDED_TIME column holds the date and time the reading was taken The TAKEN_USER_ID column holds the ID of the user taking the flowsheet reading The MEAS_VALUE column holds the reading value Task Write a query that returns one row per temperature reading made in January 2012. Return the date/time the reading was taken, the ID of the user who took the reading, and the temperature. Granularity The granularity of a table indicates what level of detail each row represents. Higher granularity means 4 • 31 Logical Expressions 88 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 more detailed, and lower granularity means less detailed. Granularity can be described technically in the terms of the data model, or it can be described in business terms. Throughout this training companion, we've been doing both. The PATIENT table has one row per patient The primary key is PAT_ID The PatientDim table has one row per patient per date range The primary key is PatientKey In these examples, the granularity of... the PATIENT table is PAT_ID or "patient" the PatientDim table is PatientKey or "patient per date range" Because the PATIENT table only has one row per patient and the PatientDim table may have more than one row per patient, the PATIENT table is said to be less granular than the PatientDim table. A proper query result must have the correct columns but must also have the correct granularity. In some cases, you'll need to change the granularity of a query result. Continuing the previous examples... PATIENT.BIRTH_DATE holds the patient's birth date PatientDim.BirthDate holds the patient's birth date, which does not change between date ranges Suppose you need to return each patient's birth date. Using the PATIENT table is as simple as: SELECT BIRTH_DATE FROM PATIENT However, using the PatientDim table, you'll end up with some patients being over represented if you use this query: SELECT BirthDate FROM PatientDim You need to reduce the granularity of the result. There are several mechanisms that can change the granularity of query results, and many will be explored in later lessons and RPT121i SQL II. In the context of this lesson, the WHERE clause can be used to change the granularity of a query result. To do so, filter on a condition that matches the granularity of the desired query result. Logical Expressions 4 • 32 RPT101i SQL I 89
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Continuing the previous examples... PatientDim.IsCurrent holds a 1 for the patient's most recent date range Because each patient has exactly one "most recent" date range, then filtering on IsCurrent = 1 will reduce the granularity of the query result to "patient". That's what we want! Our final query therefore returns the birth date of each patient only once: SELECT BirthDate FROM PatientDim WHERE IsCurrent = 1 Exercise 17: WHERE to Reduce Granularity In this exercise, you'll practice reducing the granularity of a query result by filtering. Background The EmployeeDim table has one row per employee per date range The EmployeeEpicId column holds the employee's current ID The Name column holds the employee's current name The PostalCode column holds the postal code of the employee's current residence as a character string The IsCurrent column indicates if this is the row for which every column is the most recent information for the employee 1 indicates this is the most recent information Task Write a query to return one row for each employee that currently lives in the 53753 postal code. Return the ID and Name of each matching employee. 4 • 33 Logical Expressions 90 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 The ROWNUM Pseudocolumn ﴾Oracle﴿ If you're using Oracle, you just need a little more syntax to greatly reduce the performance impact of your test queries on the database. Go to the Use Fewer Rows While Developing section of the Performance lesson now, and then return to this lesson. SQL Server folks, you were directed to this section previously. Logical Expressions 4 • 34 RPT101i SQL I 91
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Reviewing the Chapter Review Questions 1. What does a filter do to the results of a query? 2. A is TRUE, B is UNKNOWN, and C is FALSE. What does the logical expression ( A AND B ) OR NOT C evaluate to be? Choose only ONE answer. A. TRUE B. UNKNOWN C. FALSE 3. Why can't column aliases be used in the WHERE clause? Review Key 4 • 35 Logical Expressions 92 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Review Key 1. What does a filter do to the results of a query? A filter reduces the number of results by eliminating incorrect or inappropriate results 2. A is TRUE, B is UNKNOWN, and C is FALSE. What does the logical expression ( A AND B ) OR NOT C evaluate to be? Choose only ONE answer. A. TRUE B. UNKNOWN C. FALSE A. TRUE. ( TRUE AND UNKNOWN ) OR NOT FALSE = UNKNOWN OR TRUE = TRUE 3. Why can't column aliases be used in the WHERE clause? Column aliases are defined in the SELECT clause which is processed after the WHERE clause. Study Checklist Logical Expressions 4 • 36 RPT101i SQL I 93
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Study Checklist Make sure you can define the following key terms: ☐ Logical expression ☐ CASE statement ☐ WHERE clause ☐ Two‐value comparisons ☐ = Equals operator ☐ > Greater Than operator ☐ < Less Than operator ☐ >= Greater Than or Equal To operator ☐ <= Less Than or Equal To operator ☐ <> Not Equal To operator ☐ Complex comparisons ☐ BETWEEN operator ☐ IN operator ☐ LIKE operator ☐ NULL checks ☐ IS NULL operator ☐ IS NOT NULL operator ☐ Logical operators ☐ AND operator ☐ OR operator ☐ NOT operator ☐ Granularity of a table Make sure you can perform the following tasks: ☐ Compare a column with a fixed value 4 • 37 Logical Expressions 94 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 ☐ Compare a column with multiple fixed values using IN ☐ Compare a column with a string using LIKE ☐ Compare a column with a range using BETWEEN ☐ Check if a date is within a range ☐ Test for NULL values using a logical expression ☐ Negate a logical expression using NOT ☐ Compare a column with another column ☐ Compare two dates using a logical expression ☐ Combine multiple expressions using logical operators ☐ Determine whether a logical expression evaluates to TRUE, FALSE, or UNKNOWN ☐ Clarify a column's value using a CASE statement ☐ Filter rows using a logical expression Make sure you fully understand and can explain the following concepts: ☐ Logical operators return TRUE, FALSE, or UNKNOWN ☐ A logical expression must evaluate to TRUE to satisfy a condition ☐ When a query result may have unnamed columns ☐ Why column aliases are recommended for unnamed columns ☐ How precision and scale impact comparisons ☐ The WHERE clause is processed before the SELECT and ORDER BY clauses ☐ How the WHERE clause may change the granularity of a SQL result Logical Expressions 4 • 38 RPT101i SQL I 95
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Functions Introduction Function Data Flow Diagram Binary Operators Arithmetic Operators Concatenation Operator Use Functions in SQL Exercise 1: Functions and Arguments Use Functions in the SELECT Clause Use Functions in Other Clauses Discovering Functions Exercise 2: Convert Numeric to String Exercise 3: Convert Date/Time to String Exercise 4: Date/Time Functions Exercise 5: Convert Numeric to String with Formatting Exercise 6: Concatenate Strings Exercise 7: Coalesce Values Summary of Functions Arithmetic Data Type Conversion Dates and Times Strings Nulls Additional Exercises Exercise 8: Use Functions with Dates Exercise 9: Format Dates and Calculate Time Intervals 5 • 4 5 • 5 5 • 6 5 • 6 5 • 7 5 • 8 5 • 8 5 • 10 5 • 11 5 • 12 5 • 12 5 • 13 5 • 14 5 • 17 5 • 18 5 • 19 5 • 20 5 • 20 5 • 20 5 • 21 5 • 22 5 • 23 5 • 25 5 • 25 5 • 26 5 • 1 Functions 96 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Exercise 10: Many Functions Reviewing the Chapter 5 • 26 5 • 28 Functions 5 • 2 RPT101i SQL I 97
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 5 • 3 Functions 98 RPT101i SQL I
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Introduction Generating query results by simply pulling data from the database is useful, but limited. In this lesson, you will investigate different functions used in SQL queries. These will allow you to add more functionality and flexibility to your queries, by combining and manipulating data from the database in interesting ways. By the End of This Lesson, You Will Be Able To... Define the uses of SQL functions Find and use documentation for SQL functions Functions 5 • 4 RPT101i SQL I 99
EpicUUID: 5143F74D-DB01-4131-AAA3-52F4753E50D4 Function Data Flow Diagram 5 • 5 Functions 100 RPT101i SQL I