Solved

Using OR in sql query

Posted on 2009-04-08
7
202 Views
Last Modified: 2012-05-06
I have the following query that produces my desired result. The issue is, when I try to open this in design view, it removes the section that matches departments from the employee table to the jobopenings table

SELECT tblEmployees.ClockNumber, tblJobCards.Department1, tblJobCards.Department2, tblJobCards.DateTimeSigned, tblJobOpenings.JobNumber, tblEmployees.LastName, tblEmployees.FirstName
FROM (tblEmployees INNER JOIN tblJobCards ON tblEmployees.ClockNumber = tblJobCards.ClockNumber) LEFT JOIN tblJobOpenings ON

(tblJobCards.Department1 = tblJobOpenings.Department or tblJobCards.Department2 = tblJobOpenings.Department);



How can I code this so design view doesn't remove the OR condition?
0
Comment
Question by:tremak
  • 4
  • 3
7 Comments
 
LVL 22

Expert Comment

by:8080_Diver
ID: 24102488
It may be as simple as adding a missng parenthesis.  Try the following.  If that doesn't work, open the query in the design view and cut and paste what the design view shows you.
SELECT E.ClockNumber, 

       JC.Department1, 

       JC.Department2, 

       JC.DateTimeSigned, 

       JO.JobNumber, 

       E.LastName, 

       E.FirstName

FROM   tblEmployees E

INNER JOIN tblJobCards JC

   ON     E.ClockNumber = JC.ClockNumber 

LEFT JOIN tblJobOpenings JO

   ON  (JC.Department1 = JO.Department) OR

       (JC.Department2 = JO.Department);

Open in new window

0
 

Author Comment

by:tremak
ID: 24102569
After I get a message stating MS Access can't represent the join expression (tblJobCards.Department1 = tblJobOpenings.Department or tblJobCards.Department2 = tblJobOpenings.Department)

the query doesn't change, but prevents me from opening it in Query Design

0
 
LVL 22

Expert Comment

by:8080_Diver
ID: 24102629
Did you puit the query I provided into the SQL View?
Your query has the OR'ed conditions combined in one set of paarentheses and that may be where the issue is.  
Another option is to remove one of the two OR'ed conditions, open the query in design view and then try to add the condition back.
However, does the query work if you save it in the SQL View?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 22

Accepted Solution

by:
8080_Diver earned 500 total points
ID: 24102658
Come to think of it, in thinking about the manner in which the left outer join is represented in the design view, I think it may not be possible to represent that particular set of constraints using the technique that Access uses in the graphic designer.
What you may need to do is to create a second query that joins the tblJobCards and the table tblJobOpenings and then do the left outer join on that query.
0
 

Author Comment

by:tremak
ID: 24102661
Your query gave me errors so I quit trying

The query I have will work when saved in SQL view. I would just like to view in Query designer since it would make adding fields, etc easier.
0
 
LVL 22

Expert Comment

by:8080_Diver
ID: 24102688
You might want to try the second approach I suggested, i.e. the creation of the secondary query that you use in doing the left outer join.  IT is a bit of a kludge but it works around the quirk in Access that you have run into.  It also lets you add columns more easily, although you may have to add them to the secondary query first in order to be able to add them to your main query.
0
 

Author Closing Comment

by:tremak
ID: 31568295
I'll buy the second query advice. Points awarded
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now