Solved

query issue in access

Posted on 2012-04-01
8
307 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 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 15

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 15

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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 15

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 15

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Creating and Managing Databases with phpMyAdmin in cPanel.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

744 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

14 Experts available now in Live!

Get 1:1 Help Now