Solved

Syntax error on Join

Posted on 2006-11-14
23
249 Views
Last Modified: 2008-02-01
Hi.

Can anyone see the syntax error here????

SQL = "SELECT Orders.ordName, Orders.ordAddress, Orders.ordAddress2, Orders.ordCity, Orders.ordState, Orders.ordZip,"&_
    "Orders.ordCountry,Orders.ordShipName, Orders.ordShipAddress, Orders.ordShipAddress2, Orders.ordShipCity, "&_
    "Orders.ordShipState, Orders.ordShipZip, Orders.ordShipCountry, Orders.ordPhone, Orders.ordEmail, Orders.ordID,"&_
    "Orders.ordDate, Orders.ordCNum,Orders.ChargeAcctExp, Orders.OrdTotal, cart.cartQuantity, cart.cartProdID " &_
    "FROM Orders INNER JOIN Orders ON Orders.OrderID = cart.cartOrderID"
0
Comment
Question by:ClassyLinks
  • 9
  • 6
  • 6
  • +1
23 Comments
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
I guess missing a space after comman on 3rd lien before double quote.

Should be

SQL = "SELECT Orders.ordName, Orders.ordAddress, Orders.ordAddress2, Orders.ordCity, Orders.ordState, Orders.ordZip, "&_
    "Orders.ordCountry,Orders.ordShipName, Orders.ordShipAddress, Orders.ordShipAddress2, Orders.ordShipCity,  "&_
    "Orders.ordShipState, Orders.ordShipZip, Orders.ordShipCountry, Orders.ordPhone, Orders.ordEmail, Orders.ordID, "&_
    "Orders.ordDate, Orders.ordCNum,Orders.ChargeAcctExp, Orders.OrdTotal, cart.cartQuantity, cart.cartProdID  " &_
    "FROM Orders INNER JOIN Orders ON Orders.OrderID = cart.cartOrderID"
0
 
LVL 7

Author Comment

by:ClassyLinks
Comment Utility
Sorry, that didn't make a difference.

Do I need to tell it that there are two tables it is selecting FROM??

Orders & Cart??
0
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
Ok, then go back to old way

SQL = "SELECT Orders.ordName, Orders.ordAddress, Orders.ordAddress2, Orders.ordCity, Orders.ordState, Orders.ordZip, "&_
    "Orders.ordCountry,Orders.ordShipName, Orders.ordShipAddress, Orders.ordShipAddress2, Orders.ordShipCity,  "&_
    "Orders.ordShipState, Orders.ordShipZip, Orders.ordShipCountry, Orders.ordPhone, Orders.ordEmail, Orders.ordID, "&_
    "Orders.ordDate, Orders.ordCNum,Orders.ChargeAcctExp, Orders.OrdTotal, cart.cartQuantity, cart.cartProdID  " &_
    "FROM Orders,cart where Orders.OrderID = cart.cartOrderID"

0
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
Also I guess you need one space between ampersand and underscore

SQL = "SELECT Orders.ordName, Orders.ordAddress, Orders.ordAddress2, Orders.ordCity, Orders.ordState, Orders.ordZip, "& _
    "Orders.ordCountry,Orders.ordShipName, Orders.ordShipAddress, Orders.ordShipAddress2, Orders.ordShipCity,  "& _
    "Orders.ordShipState, Orders.ordShipZip, Orders.ordShipCountry, Orders.ordPhone, Orders.ordEmail, Orders.ordID, "& _
    "Orders.ordDate, Orders.ordCNum,Orders.ChargeAcctExp, Orders.OrdTotal, cart.cartQuantity, cart.cartProdID  " & _
    "FROM Orders INNER JOIN Orders ON Orders.OrderID = cart.cartOrderID"

0
 
LVL 7

Author Comment

by:ClassyLinks
Comment Utility
sorry...same error.

if I add the "cart" in the From  (FROM Orders,Cart)

I get
Cannot repeat table name 'Orders' in FROM clause.
0
 
LVL 4

Expert Comment

by:ETA-TECHNICIANS
Comment Utility
I think you have your syntax mixed up.
You are trying to join incorrctly.  Change the INNER JOIN portion to:

INNER JOIN cart ON cart.cartOrderID = Orders.OrderID
0
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
>>I get
Cannot repeat table name 'Orders' in FROM clause.

Could you post me the code. ALso I asked you to put spaces between ampersand and underscore
0
 
LVL 7

Author Comment

by:ClassyLinks
Comment Utility
Current code is now:

SQL = "SELECT Orders.ordName, Orders.ordAddress, Orders.ordAddress2, Orders.ordCity, Orders.ordState, Orders.ordZip, "& _
    "Orders.ordCountry,Orders.ordShipName, Orders.ordShipAddress, Orders.ordShipAddress2, Orders.ordShipCity,  "& _
    "Orders.ordShipState, Orders.ordShipZip, Orders.ordShipCountry, Orders.ordPhone, Orders.ordEmail, Orders.ordID, "& _
    "Orders.ordDate, Orders.ordCNum,Orders.ChargeAcctExp, Orders.OrdTotal, cart.cartQuantity, cart.cartProdID " & _
    "FROM Orders INNER JOIN Cart ON  cart.cartOrderID = Orders.OrderID"


Error:
No value given for one or more required parameters.
0
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
Check teh column names. Probably one or more does not exists
0
 
LVL 4

Expert Comment

by:ETA-TECHNICIANS
Comment Utility
What do you get when you try:

SQL = "SELECT * FROM Orders INNER JOIN Cart ON  cart.cartOrderID = Orders.OrderID"

If this works, then I would add the specific columns in a few at a time to try and isolate the issue.
0
 
LVL 7

Author Comment

by:ClassyLinks
Comment Utility
That still gives a Syntax error in JOIN operation.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 4

Expert Comment

by:ETA-TECHNICIANS
Comment Utility
What type of DB are you using?
0
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
Are the columns names ok in the join ?
0
 
LVL 4

Expert Comment

by:ETA-TECHNICIANS
Comment Utility
I also noticed you name the Order ID in the order table to different things.  During the SELECT portion you call it Orders.ordID while in the JOIN you call it Orders.OrderID.  This discrepancy may be the root of your issue.
0
 
LVL 31

Expert Comment

by:alorentz
Comment Utility
There is no syntax error in the SQL you are posting...perhaps the error is on different code...
0
 
LVL 7

Author Comment

by:ClassyLinks
Comment Utility
Ok...
Access Db.


Thanks ETA for the typo.  it is supposed to be: Orders.ordid

So...

The simple version of the query would be

    SQL = "SELECT * FROM Orders INNER JOIN Cart ON  cart.cartOrderID = Orders.OrdID"

But that is still giving me the syntax error.
0
 
LVL 4

Expert Comment

by:ETA-TECHNICIANS
Comment Utility
If I remember correctly, Access doesn't like INNER JOINs - just use a JOIN
0
 
LVL 20

Accepted Solution

by:
jitganguly earned 500 total points
Comment Utility
I mentioned it to you before
>>Are the columns names ok in the join ?


Try with braces

 SQL = "SELECT * FROM [Orders] INNER JOIN [Cart] ON  [cart].cartOrderID = [Orders].OrdID"
0
 
LVL 4

Expert Comment

by:ETA-TECHNICIANS
Comment Utility
The other thing to be careful with is data types.  You can easily cast in Access by using Int(exp).
Make sure you are comparing the same type of data.
An easy way to test is to open the DB locally and write out the query and debug it that way.
Once you have it working, trasnfer the query into your code and test there.
0
 
LVL 31

Expert Comment

by:alorentz
Comment Utility
What version of Access?
0
 
LVL 7

Author Comment

by:ClassyLinks
Comment Utility
:)

I'm not sure how it worked, but it did!!

I changed to:

SQL = "SELECT Orders.*, cart.cartQuantity, cart.cartProdID " & _
    "FROM [Orders] INNER JOIN [Cart] ON [cart].cartOrderID = [Orders].OrdID"

And now it works.

Thank you all for your help.

How do you feel about splitting points?
0
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
Well you have used my last suggestion of using braces. I deserve full points here
0
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
Thanks
0

Featured Post

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

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

6 Experts available now in Live!

Get 1:1 Help Now