SQL JOIN syntax error

manared

Well-known member
Joined
Jun 1, 2006
Messages
84
Programming Experience
1-3
Alright, I'm creating a web app in vb.net 2005 and I have a SQL statement that I guess is not correct. I was wondering if anyone can help me or see a problem. I get the error "Syntax error in JOIN operation" Here is my SQL statement:

VB.NET:
[SIZE=2]lblSqlStatement.Text = [/SIZE][SIZE=2][COLOR=#800000]"SELECT QuoteMaster.ID, QuoteMaster.QuoteNumber, Customer.CustomerName, QuoteForecast.Description FROM ((QuoteMaster INNER JOIN QuoteEquipment ON QuoteMaster.ID = QuoteEquipment.QuoteID) INNER JOIN (Customer ON QuoteMaster.BuyerID = Customer.ID) INNER JOIN QuoteForecast ON QuoteMaster.ID = QuoteForecast.ID WHERE ((QuoteEquipment.Description)= '"[/COLOR][/SIZE][SIZE=2] & ddlEquipment.SelectedItem.Text & [/SIZE][SIZE=2][COLOR=#800000]"' ));"
[/COLOR][/SIZE]

I have several other statements similar to this that are working just fine. They use maybe one different table, so they are different, but I'm confused on this one. Let me know if anyone needs more code or any more explanation. Thank you!!!
 
Well, I figured it out.. Where my parenthesis were located was the problem. This is my SQL statement now and it works fine:

VB.NET:
lblSqlStatement.Text = "SELECT QuoteMaster.ID, QuoteMaster.QuoteNumber, Customer.CustomerName, QuoteForecast.Description FROM (((QuoteMaster INNER JOIN QuoteEquipment ON QuoteMaster.ID = QuoteEquipment.QuoteID) INNER JOIN Customer ON QuoteMaster.BuyerID = Customer.ID) INNER JOIN QuoteForecast ON QuoteMaster.ID = QuoteForecast.ID) WHERE (QuoteEquipment.Description= '" & ddlEquipment.SelectedItem.Text & "');"

Just thought I'd post this to help anyone else out.
 
databases typically dont require (and in oracle's case - particularly dislike) brackets around joins..

SELECT ... FROM ... JOIN... JOIN... WHERE (brackets if using OR tests)
 
Actually, I tried using no parenthesis in the FROM statement, and it kept saying that I'm missing an operator. I used no parenthesis and I also tried using one set around the whole FROM clause and it still didn't work, so I do need the parenthesis around each INNER JOIN in my statement.
 
Oops!! my bad... no parenthesis in the FROM clause will work, but if you use parenthesis, you have to use them all for each INNER JOIN. Sorry about that!
 
Back
Top