1

Error :-

Syntax error (missing operator) in query expression 'PriceHistory.UnitPriceId = ProductPrice.UnitPriceId inner join Prdc on prdc.prdcID=ProductPrice.PrdcId'

Used script :-

string sql = "select PriceHistory.UnitSellRate," +
    "PriceHistory.DateAssigned, PriceHistory.DateChanged, PriceHistory.MRP, PriceHistory.ProductOffer " +
     "from ProductPrice " +
     "inner join PriceHistory on PriceHistory.UnitPriceId = ProductPrice.UnitPriceId " +
     "inner join Prdc on prdc.prdcID=ProductPrice.PrdcId";
     "left join Suppliers on Suppliers.supplierId = Products.SupplierId ";
     " where Products.ProductCode='" + productCode + "'";
3
  • First of all, you have a couple of ; where you need + -- I assume you mis-copied your code? Commented Nov 19, 2010 at 15:46
  • Thanks a lot .. my query changed as follows,but still i am getting same error :( Commented Nov 19, 2010 at 15:51
  • Script :- "select PriceHistory.UnitSellRate," + "PriceHistory.DateAssigned,PriceHistory.DateChanged,PriceHistory.MRP,PriceHistory.ProductOffer " + "from ProductPrice " + "inner join PriceHistory on PriceHistory.UnitPriceId = ProductPrice.UnitPriceId " + "inner join Prdc on prdc.prdcID=ProductPrice.PrdcId"+ "left join Suppliers on Suppliers.supplierId = Products.SupplierId "+ " where Products.ProductCode='" + productCode + "'"; Commented Nov 19, 2010 at 15:51

2 Answers 2

1

You need a space before the end of your quotes

string sql = "select PriceHistory.UnitSellRate," + 
"PriceHistory.DateAssigned, PriceHistory.DateChanged, PriceHistory.MRP, PriceHistory.ProductOffer " + 
 "from ProductPrice " + 
 "inner join PriceHistory on PriceHistory.UnitPriceId = ProductPrice.UnitPriceId " + 
 "inner join Prdc on prdc.prdcID=ProductPrice.PrdcId " + 
 "left join Suppliers on Suppliers.supplierId = Products.SupplierId " +
 " where Products.ProductCode='" + productCode + "'"; 
Sign up to request clarification or add additional context in comments.

11 Comments

string sql = "select PriceHistory.UnitSellRate," + "PriceHistory.DateAssigned,PriceHistory.DateChanged,PriceHistory.MRP,PriceHistory.ProductOffer " + "from ProductPrice " + "inner join PriceHistory on PriceHistory.UnitPriceId = ProductPrice.UnitPriceId " + "inner join Prdc on prdc.prdcID = ProductPrice.PrdcId " + "left join Suppliers on Suppliers.supplierId = Products.SupplierId " + " where Products.ProductCode= '" + productCode + "'";
Still getting the same error. select PriceHistory.UnitSellRate,PriceHistory.DateAssigned,PriceHistory.DateChanged,PriceHistory.MRP,PriceHistory.ProductOffer from ProductPrice inner join PriceHistory on PriceHistory.UnitPriceId = ProductPrice.UnitPriceId inner join Prdc on prdc.prdcID = ProductPrice.PrdcId left join Suppliers on Suppliers.supplierId = Prdc.SupplierId where Prdc.ProductCode = 'df'
Here, make your life easy by wriling long sql strings like this: string sql = @"select PriceHistory.UnitSellRate, PriceHistory.DateAssigned, PriceHistory.DateChanged, PriceHistory.MRP, PriceHistory.ProductOffer from ProductPrice inner join PriceHistory on PriceHistory.UnitPriceId = ProductPrice.UnitPriceId inner join Prdc on prdc.prdcID=ProductPrice.PrdcId left join Suppliers on Suppliers.supplierId = Products.SupplierId where Products.ProductCode = '"+ productCode + "'";
Why are you joining to supplier and product price if all the fields you are selecting are from the pricehistory table? Surely you can do this: SELECT PH.UnitSellRate, PH.DateAssigned, PH.DateChanged, PH.MRP, PH.ProductOffer from PriceHistory AS PH inner join Prdc AS P on P.prdcID = PH.PrdcId where P.ProductCode = 'df'
Script :- select PriceHistory.UnitSellRate, PriceHistory.DateAssigned, PriceHistory.DateChanged, PriceHistory.MRP, PriceHistory.ProductOffer, Suppliers.SupplierName from ProductPrice inner join PriceHistory on PriceHistory.UnitPriceId = ProductPrice.UnitPriceId inner join Prdc on prdc.prdcID = ProductPrice.PrdcId left join Suppliers on Suppliers.supplierId = Prdc.SupplierId where Prdc.ProductCode = '" + productCode + "'";
|
1

There seem to be two main problems that I can see (other than the spacing and semicolon problems already identified):

1 - Access/Jet requires parentheses when performing more than one join. Basically, you need to essentially make up subqueries to ensure you're only joining two tables at a time, so instead of this:

SELECT 
        PriceHistory.UnitSellRate,
        PriceHistory.DateAssigned, 
        PriceHistory.DateChanged, 
        PriceHistory.MRP, 
        PriceHistory.ProductOffer
FROM
        ProductPrice
           INNER JOIN PriceHistory 
           ON PriceHistory.UnitPriceId = ProductPrice.UnitPriceId

           INNER JOIN Prdc
           ON prdc.prdcID=ProductPrice.PrdcId

...you need to wrap those inner joins in parentheses to create join two tables into one, that will then be joined to one more, etc, like this:

 SELECT 
    PriceHistory.UnitSellRate,
    PriceHistory.DateAssigned, 
    PriceHistory.DateChanged, 
    PriceHistory.MRP, 
    PriceHistory.ProductOffer
 FROM
 (ProductPrice INNER JOIN PriceHistory 
              ON PriceHistory.UnitPriceId = ProductPrice.UnitPriceId)
 INNER JOIN Prdc 
 ON prdc.prdcID=ProductPrice.PrdcId

2 - I'm not really sure what you're joining at the end with your LEFT JOIN. That LEFT JOIN is trying to join the Suppliers and Products tables, but neither of them seem to have any connection to anything in the INNER JOINs you've already made. Is it possible that Prdc and Products are the same table?

1 Comment

Was having this same issue, and wrapping the table and first inner join in parenthases worked for me!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.