Solved

Using OR in sql query

Posted on 2009-04-08
7
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

738 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