Solved

Using OR in sql query

Posted on 2009-04-08
7
201 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 22

Accepted Solution

by:
8080_Diver earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I'll buy the second query advice. Points awarded
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Sql Query Lookup based on range 2 28
mySql Syntax 7 26
how to do this MS SQL script? 11 48
How to Add / Edit Windows Menu 4 23
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 …
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

771 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

16 Experts available now in Live!

Get 1:1 Help Now