Solved

Syntax error on Join

Posted on 2006-11-14
23
255 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
[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
  • 9
  • 6
  • 6
  • +1
23 Comments
 
LVL 20

Expert Comment

by:jitganguly
ID: 17940225
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
ID: 17940256
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
ID: 17940265
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
Independent Software Vendors: 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 20

Expert Comment

by:jitganguly
ID: 17940281
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
ID: 17940337
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
ID: 17940341
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
ID: 17940346
>>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
ID: 17940370
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
ID: 17940382
Check teh column names. Probably one or more does not exists
0
 
LVL 4

Expert Comment

by:ETA-TECHNICIANS
ID: 17940390
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
ID: 17940405
That still gives a Syntax error in JOIN operation.
0
 
LVL 4

Expert Comment

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

Expert Comment

by:jitganguly
ID: 17940416
Are the columns names ok in the join ?
0
 
LVL 4

Expert Comment

by:ETA-TECHNICIANS
ID: 17940432
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
ID: 17940444
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
ID: 17940493
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
ID: 17940520
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
ID: 17940530
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
ID: 17940558
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
ID: 17940745
What version of Access?
0
 
LVL 7

Author Comment

by:ClassyLinks
ID: 17940837
:)

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
ID: 17940853
Well you have used my last suggestion of using braces. I deserve full points here
0
 
LVL 20

Expert Comment

by:jitganguly
ID: 17940904
Thanks
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

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 informatio…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

631 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