开发者

How to resolve Syntax error (missing operator) error while using the Access as db for C# Windows application?

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='" + p开发者_如何学GoroductCode + "'";


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 + "'"; 


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜