sentricworkforce query builder: joins and tables

of 63 /63
Sentric Workforce Query Builder Working with Table Joins Sentric, Inc.

Author: sentrictraining

Post on 15-Aug-2015

77 views

Category:

Software


2 download

Embed Size (px)

TRANSCRIPT

  1. 1. Sentric Workforce Query Builder Working with Table Joins Sentric, Inc.
  2. 2. Josh Davis Sentric Product Support Supervisor My Credentials: Over 17 years experience in HRIS Questions? Hang on until the end, well have 15 minutes of Q&A Or email me at [email protected]
  3. 3. Webinar How To I will not be able to hear you during the webinar until we get to the question and answer portion, but you have some tools to tell me if you need some help. By your attendee status are some status icons to help me know if you need me to speak up or speak more softly. You can also put out the life saver to tell me if you need some assistance. To view the presentation in full screen click the expansion icon in the upper right corner.
  4. 4. This Webinar presents advanced material The presentation you are attending presents advanced material about query development. The concepts and information presented are intended for experienced report designers and experienced Query Builder designers. If you find the material is hard to understand I recommend that you keep working with Query Builder and asking questions. This webinar is being recorded and can be reviewed by going to the Sentric website.
  5. 5. Agenda Joins and data Inner join versus Outer join Taking joins to end of the line Joins and Criteria Filters Adding a filter to a Join
  6. 6. Joins and Data
  7. 7. Joins and Data
  8. 8. Joins and Data Important background 1. SQL Server supports Relational Databases 2. Relational databases are made up of numerous tables that are related or joined to one another by key fields
  9. 9. Joins and Data Like a Dot to Dot puzzle the tables like the dots of the puzzle do not make much sense without the connections. Connecting the dots incorrectly produces an incorrect picture!
  10. 10. Joins and Data
  11. 11. Inner Joins Versus Outer Joins
  12. 12. Inner Joins Versus Outer Joins
  13. 13. Inner Joins Versus Outer Joins Missing Data Poll
  14. 14. Inner Joins Versus Outer Joins Common Joins 1. Inner Join 2. Outer Join 1. Left Outer Join 2. Right Outer Join
  15. 15. Inner Joins Versus Outer Joins Inner Join 1. Only data with key value in each table return a record Table A Key Field ID First Name Last Name 1 John Smith 2 Fred Jones 3 Susan Brand 4 Ellen Sanders Table B Key Field ID Dependent First Name Dependent Last Name 1 Julie Smith 1 Brock Smith 4 Ethan Sanders Results of Inner Join Statement Key Field ID First Name Last Name Dependent First Name Dependent Last Name 1 John Smith Julie Smith 1 John Smith Brock Smith 4 Ellen Sanders Ethan Sanders Select [Table A].[First Name], [Table A].[Last Name],[Table B].[Dependent First Name],[Table B].[Dependent Last Name] From [Table A] INNER JOIN [Table B] ON [Table A].[Key Field ID] = [Table B].[Key Field ID]
  16. 16. Inner Joins Versus Outer Joins Left Outer Join 1. All data in Left table returned with matching data from right table Table A Key Field ID First Name Last Name 1 John Smith 2 Fred Jones 3 Susan Brand 4 Ellen Sanders Table B Key Field ID Dependent First Name Dependent Last Name 1 Julie Smith 1 Brock Smith 4 Ethan Sanders Results of Left Outer Join Statement Key Field ID First Name Last Name Dependent First Name Dependent Last Name 1 John Smith Julie Smith 1 John Smith Brock Smith 2 Fred Jones 3 Susan Brand 4 Ellen Sanders Ethan Sanders Select [Table A].[First Name], [Table A].[Last Name],[Table B].[Dependent First Name],[Table B].[Dependent Last Name] From [Table A] LEFT OUTER JOIN [Table B] ON [Table A].[Key Field ID] = [Table B].[Key Field ID]
  17. 17. Inner Joins Versus Outer Joins Right Outer Join 1. All data in Right table returned with matching data from left table Table A Key Field ID First Name Last Name 1 John Smith 2 Fred Jones 3 Susan Brand 4 Ellen Sanders Table B Key Field ID Dependent First Name Dependent Last Name 1 Julie Smith 1 Brock Smith 4 Ethan Sanders Results of Right Outer Join Statement Key Field ID First Name Last Name Dependent First Name Dependent Last Name 1 John Smith Julie Smith 1 John Smith Brock Smith 4 Ellen Sanders Ethan Sanders Select [Table A].[First Name], [Table A].[Last Name],[Table B].[Dependent First Name],[Table B].[Dependent Last Name] From [Table A] RIGHT OUTER JOIN [Table B] ON [Table A].[Key Field ID] = [Table B].[Key Field ID]
  18. 18. Inner Joins Versus Outer Joins Example from Sentric Workforce Query Builder 1. Show me all active employees and their emergency contacts if they have any in the system.
  19. 19. Inner Joins Versus Outer Joins Example from Sentric Workforce Query Builder 1. Notice that all the records have Emergency Contact data and there are 101 records
  20. 20. Inner Joins Versus Outer Joins Example from Sentric Workforce Query Builder 1. Change the record to a Left Outer Join to see all active employees whether or not they have an Emergency Contact.
  21. 21. Inner Joins Versus Outer Joins Example from Sentric Workforce Query Builder 1. Now looking at the results there are 165 records and active employees with no emergency contact show blank fields from that table
  22. 22. Inner Joins Versus Outer Joins
  23. 23. Taking Joins to the End of the Line
  24. 24. Inner Joins Versus Outer Joins Outer Joins Poll
  25. 25. Taking Joins to the End of the Line
  26. 26. Taking Joins to the End of the Line Using Outer Joins can sometimes get tricky 1. Imagine this scenario Trying to create a query showing all active employees and their emergency contacts if they have any with the state name the contact lives in You make the outer join from tPerson to tPersonEmergency run the query and it all looks good You then link in the state code table add the description of the state, but when you run the query the data is not right all the people with no emergency contacts have been removed This occurs because the new join is a INNER JOIN and since there is no record in tPersonEmergency the connection to the StateProv Code table removes the records because with an inner join the value must exist on both ends of the join
  27. 27. Taking Joins to the End of the Line When using Outer Joins all the joins to the end of the string need to be outer joins too
  28. 28. Joins and Criteria Filters
  29. 29. Inner Joins Versus Outer Joins SQL Tab Poll
  30. 30. Joins and Criteria Filters Adding a filter to the table on the Right side of a Left Outer Join will invalidate the Outer Join When you add a filter it only returns the records where the filter is true
  31. 31. Joins and Criteria Filters To see everyone who does not have an Emergency Contact who lives in Pennsylvania, if you set a filter to say StateProvCode PA that would invalidate the outer join and employees without a StateProvCode value would no longer show up To avoid this problem change the criteria to also return null values
  32. 32. Joins and Criteria Filters The Criteria panel is not configured to allow a NULL value filter as you can see below
  33. 33. Joins and Criteria Filters A NULL value criteria statement needs to be added on the SQL tab In a SQL statement the WHERE clause defines the criteria applied to the entire SQL Select Statement
  34. 34. Joins and Criteria Filters The Basics of a SQL Select Statement
  35. 35. Joins and Criteria Filters To add a NULL criteria 1. Find the value that is in the code currently that can also be null 2. Note that in Query Builder filter Statements are enclosed in Parenthesis and a set is also added from the beginning of the where clause to the end of each portion
  36. 36. Joins and Criteria Filters To add a NULL criteria 3. Add an OR for a null value to the criteria for the outer joined table
  37. 37. Joins and Criteria Filters To add a NULL criteria 4. By adding the OR IS NULL criteria the left outer join becomes valid again
  38. 38. Joins and Criteria Filters
  39. 39. Adding a Filter to a Join
  40. 40. Adding a Filter to a Join Sometimes adding NULL does not work 1. Here is a scenario you want to see all your active employees and see who is enrolled in the medical plan and who is not 2. If you set up a filter to say the benefit plan is Medical or it null this does not work because an employee may not be in medical but they may have life insurance, vision coverage or dental 3. NULL only works where either there is a record or there is not one
  41. 41. Adding a Filter to a Join Use Null Filter Does a record exist in the table for this person or not Emergency contacts or any dependent In WHERE Clause Use Join Filter Specific type of record Specific absence or benefit plan In FROM Clause
  42. 42. Adding a Filter to a Join Examples of a query where you would use Join Filter Show ALL active employees show their Voluntary Employee Life coverage amount if they are enrolled Show ALL active employees show the name of their spouse if they are married
  43. 43. Joins and Criteria Filters Query to get Employee and Spouse Step 1
  44. 44. Joins and Criteria Filters Query to get Employee and Spouse Step 1
  45. 45. Joins and Criteria Filters Query to get Employee and Spouse Step 1
  46. 46. Joins and Criteria Filters Query to get Employee and Spouse Step 2 change inner joins to Left outer joins SELECT TOP 99999999 [tPerson].[PersonGUID] AS [Person GUID], [tPerson].[FullName] AS [Full Name], [Dependent].[FullName] AS [Dependent Full Name], [tRelationship].[RelationshipDescription] AS [Relationship Description], [tRelationship].[SpousalEquivalencyFlag] AS [Spousal Equivalency Flag] FROM [tPerson] INNER JOIN [tPersonStatusHist] ON [tPerson].[PersonGUID] = [tPersonStatusHist].[PersonGUID] LEFT OUTER JOIN [tPersonDependent] ON [tPerson].[PersonGUID] = [tPersonDependent].[PersonGUID] INNER JOIN [tStatus] ON [tPersonStatusHist].[StatusCode] = [tStatus].[StatusCode] LEFT OUTER JOIN [tPerson] AS [Dependent] ON [tPersonDependent].[DependentPersonGUID] = [Dependent].[PersonGUID] LEFT OUTER JOIN [tRelationship] ON [tPersonDependent].[RelationshipCode] = [tRelationship].[RelationshipCode] WHERE (([tPersonStatusHist].PersonStatusCurrentFlag = '1') AND ([tStatus].ActiveFlag = '1'))
  47. 47. Joins and Criteria Filters Query to get Employee and Spouse Step 2
  48. 48. Joins and Criteria Filters Query to get Employee and Spouse If you make the MISTAKE of adding the filter in the filter pane
  49. 49. Joins and Criteria Filters Query to get Employee and Spouse Your results will only show employees with spouses NOT THE DESIRED RESULT!
  50. 50. Joins and Criteria Filters Query to get Employee and Spouse If you try and add the IS NULL Filter to fix this you may be fooled into thinking the data is correct Results that show all Active with All Dependents Results with spouse or NULL filter
  51. 51. Joins and Criteria Filters Query to get Employee and Spouse Step 3 To complete this query correctly, changes will need to be made in the SQL tab NOTE: Once changes are made in the SQL tab the query will no longer be updatable in the design tab If a filter is added to the LEFT OUTER JOIN the system will return all the records from the right side table and only the matching filtered records from the table on the left side LEFT OUTER JOIN [tPersonDependent] ON [tPerson].[PersonGUID] = [tPersonDependent].[PersonGUID] AND [tPersonDependent].[RelationshipCode] IN ('SP', 'HU', 'WF')
  52. 52. Joins and Criteria Filters Query to get Employee and Spouse Step 3
  53. 53. Joins and Criteria Filters Query to get Employee and Spouse Step 3
  54. 54. The more you understand the joins the clearer the picture becomes
  55. 55. The more you understand the joins the clearer the picture becomes
  56. 56. The more you understand the joins the clearer the picture becomes
  57. 57. The more you understand the joins the clearer the picture becomes
  58. 58. The more you understand the joins the clearer the picture becomes
  59. 59. The more you understand the joins the clearer the picture becomes
  60. 60. The more you understand the joins the clearer the picture becomes
  61. 61. Absences Test Your Knowledge
  62. 62. Questions If you would like to ask a question please enter your question in the Chat box
  63. 63. Thank You for attending! Please take the survey following the Webinar