Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Syntax error on Join

Posted on 2006-11-14
23
Medium Priority
?
256 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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

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!

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…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

670 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