Solved

query issue in access

Posted on 2012-04-01
8
311 Views
Last Modified: 2012-04-01
i have this query but it is showing me an error when i run it, it seems ok to me

SELECT contactDetails.*, categories.catName as MainCat ,titles.title FROM contactDetails WHERE 1=1 LEFT JOIN Categories ON contactDetails.categoryid = Categories.catID LEFT join titles on titles.titleID = contactDetails.titles AND Activated = (param 1) ORDER BY contactID DESC

Error i am getting is:

Error Executing Database Query.

Syntax error (missing operator) in query expression '1=1 LEFT JOIN Categories ON contactDetails.categoryid = Categories.catID LEFT join titles on titles.titleID = contactDetails.titles AND Activated = ?'
0
Comment
[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
8 Comments
 
LVL 57
ID: 37793585
Where clause comes last:

SELECT contactDetails.*, categories.catName as MainCat, titles.title FROM contactDetails LEFT JOIN Categories ON contactDetails.categoryid = Categories.catID LEFT join titles on titles.titleID = contactDetails.titles WHERE 1=1 AND Activated = [param 1] ORDER BY contactID DESC

  A nice way to learn SQL in Access is to construct the query in the query designer, then switch to SQL view.  You can see the resulting SQL and cut & paste to where needed.

Jim
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 37793605
oops that was my mistake actual this is the error message i am getting:

Error Executing Database Query.

Syntax error (missing operator) in query expression 'contactDetails.categoryid = Categories.catID LEFT join titles on titles.titleID = contactDetails.titles'.
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 37793607
here it is a change

SELECT contactDetails.*, categories.catName as MainCat ,titles.title FROM contactDetails LEFT JOIN Categories ON contactDetails.categoryid = Categories.catID LEFT join titles on titles.titleID = contactDetails.titles WHERE 1=1 AND Activated = 'True' ORDER BY contactID DESC
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:OCDan
ID: 37793615
SELECT contactDetails.*,
         categories.catName AS MainCat,
         titles.title
FROM contactDetails
              LEFT JOIN Categories ON contactDetails.categoryid = Categories.catID
              LEFT JOIN titles ON titles.titleID = contactDetails.titles
             AND Activated = 'True'
ORDER BY contactID DESC

There is no need for the where clause, 1=1 will always be true, so just leave it out.
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 37793626
i have to apply a where clause so tried clause is:

 SELECT contactDetails.*, categories.catName as MainCat ,titles.title FROM contactDetails LEFT JOIN Categories ON contactDetails.categoryid = Categories.catID LEFT join titles on titles.titleID = contactDetails.titles WHERE Activated = 'True' ORDER BY contactID DESC

The thing is that the statement has <cfif> attached so have to use the where clause

Still getting the clause:

Error Executing Database Query.

Syntax error (missing operator) in query expression 'contactDetails.categoryid = Categories.catID LEFT join titles on titles.titleID = contactDetails.titles'.
0
 
LVL 9

Accepted Solution

by:
OCDan earned 500 total points
ID: 37793634
Here you are mate, works for me at least.

SELECT contactDetails.*,
         categories.catName AS MainCat,
         titles.title
FROM (contactDetails
LEFT JOIN Categories ON contactDetails.categoryid = Categories.catID)
LEFT JOIN titles on titles.titleid = contactDetails.titles
WHERE Activated = (param 1)
ORDER BY contactID DESC
0
 
LVL 16

Author Closing Comment

by:Gurpreet Singh Randhawa
ID: 37793681
yeah, Braces did work, don no why issue with access
0
 
LVL 10

Expert Comment

by:plummet
ID: 37793690
Try and cut the query down, see if it works and then add parts back in, eg start with

SELECT 
   contactDetails.*, 
  categories.catName as MainCat 
FROM contactDetails LEFT JOIN Categories 
  ON contactDetails.categoryid = Categories.catID

Open in new window

If that works, then:

SELECT 
   contactDetails.*, 
  categories.catName as MainCat 
FROM contactDetails LEFT JOIN Categories 
  ON contactDetails.categoryid = Categories.catID
LEFT join titles on titles.titleID = contactDetails.titles 
ORDER BY contactID DESC

Open in new window

Are you sure the field names are correct, especially contactDetails.titles? Sure it's not  contactDetails.titleID?

Is Activated a Yes/No (boolean) field? Or a text field?
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

752 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