Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

query issue in access

Posted on 2012-04-01
8
Medium Priority
?
315 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
8 Comments
 
LVL 58
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 2000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

972 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