Solved

Using OR in sql query

Posted on 2009-04-08
7
203 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

831 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