Melissa S. Christ
Melissa S. Christ

Reputation: 49

Syntax error (missing operator) in query expression ''

I'm getting this particular error for a couple hours now and I still can't figure out for the life of me what's wrong with my select statement, I'm trying to connect 3 tables.

"SELECT POItem.PO AS 'Purchase_Order', POItem.Qty AS 'Quantity', 
POItem.BCurr as 'Currency', POItem.TotalCost, PO.Vendor, Master.Desc1 
FROM PO 
LEFT JOIN POItem ON PO.ID = POItem.PO AND 
INNER JOIN Master ON Master.IPN = POItem.IPN 
WHERE POItem.IPN = '" & TextBox1.Text & "' 
ORDER BY POItem.PO DESC"

Upvotes: 1

Views: 1034

Answers (1)

Markus
Markus

Reputation: 22456

There is a AND keyword that is not necessary at this position (just in front of INNER JOIN). If you remove it and add brackets around the LEFT JOIN, your query should work:

"SELECT POItem.PO AS 'Purchase_Order', POItem.Qty AS 'Quantity', 
POItem.BCurr as 'Currency', POItem.TotalCost, PO.Vendor, Master.Desc1 
FROM (PO 
LEFT JOIN POItem ON PO.ID = POItem.PO) 
INNER JOIN Master ON Master.IPN = POItem.IPN 
WHERE POItem.IPN = '" & TextBox1.Text & "' 
ORDER BY POItem.PO DESC"

By the way, instead of including the value of TextBox1.Text in the string, rather use Parameters in order to avoid SQL injection attacks.

Upvotes: 3

Related Questions