Advertisement

09.06.2007 at 12:44PM PDT, ID: 22811845
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

MS SQL Left Outer Join - too few records

Asked by DerryLyons in MS SQL Server, Microsoft Access Database, SQL Query Syntax

Tags: , , , ,

I can see the concept has been asked before re: left outer joins, but I just can't get it connected in my brain. I'll try to strike a balance between the technical table structures and describing the issue. (BTW, I'm experiencing the same issue creating queries in MS Access and creating views in MSSQL...)

I have a set of employees (TM_EMPS, TM_EMP_INFO, DEPTS) that need to be printed on a monthly timesheet whether they have taken leave (TM_LEAVE_HISTORY, TM_CALENDAR, TM_LEAVE_LOOKUP) or not. I'll specify a period (TM_CALENDAR.CAL_PERIOD) to reduce the result set to only this pay period, but I only get records back for employees who have requested leave.

I tried creating two queries in Access (which return the correct respective recordsets: all employees in query1 and leave records for the month in query2), and the result is still just the emps who have requested leave.

Here's the view created in MSSQL Server:

SELECT     TOP 100 PERCENT dbo.TM_EMP_INFO.EMP_ID, dbo.TM_EMP_INFO.EMP_LAST, dbo.TM_EMP_INFO.EMP_FIRST, dbo.TM_EMP_INFO.EMP_LOC,
                      dbo.DEPTS.DEPT_NAME, dbo.TM_CALENDAR.CAL_PERIOD, dbo.TM_LEAVE_HISTORY.LV_DATE
FROM         dbo.TM_EMP_INFO INNER JOIN
                      dbo.DEPTS ON dbo.TM_EMP_INFO.EMP_LOC = dbo.DEPTS.DEPT_CODE INNER JOIN
                      dbo.TM_EMPS ON dbo.TM_EMP_INFO.EMP_ID = dbo.TM_EMPS.TM_EMP_ID LEFT OUTER JOIN
                      dbo.TM_LEAVE_LOOKUP INNER JOIN
                      dbo.TM_LEAVE_HISTORY ON dbo.TM_LEAVE_LOOKUP.TM_LV_CODE = dbo.TM_LEAVE_HISTORY.LV_TYPE INNER JOIN
                      dbo.TM_CALENDAR ON dbo.TM_LEAVE_HISTORY.LV_DATE = dbo.TM_CALENDAR.CAL_DATE ON
                      dbo.TM_EMP_INFO.EMP_ID = dbo.TM_LEAVE_HISTORY.LV_EMP_ID
WHERE     (dbo.TM_EMPS.TM_TIMESHEET = 1) AND (dbo.TM_LEAVE_LOOKUP.TM_LV_DISPLAY = 1) AND (dbo.TM_CALENDAR.CAL_PERIOD = 200709)
ORDER BY dbo.DEPTS.DEPT_NAME, dbo.TM_EMP_INFO.EMP_LAST, dbo.TM_EMP_INFO.EMP_FIRST

I read someplace else about specifying criteria for WHERE vs ON... not sure if that's the right direction. Let me know if you need more info (table structures, etc.) Thanks! :) DerryStart Free Trial
[+][-]09.06.2007 at 01:27PM PDT, ID: 19843434

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL Server, Microsoft Access Database, SQL Query Syntax
Tags: outer, left, access, ms, sql
Sign Up Now!
Solution Provided By: folderol
Participating Experts: 2
Solution Grade: A
 
 
[+][-]09.06.2007 at 01:45PM PDT, ID: 19843560

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]09.06.2007 at 02:32PM PDT, ID: 19843879

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.07.2007 at 03:23PM PDT, ID: 19851389

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-44 / EE_QW_2_20070628