2010-11-19 22 views
1

Hata: -C# Windows uygulaması için Access olarak db kullanılırken sözdizimi hatası (eksik operatör) hatası nasıl çözülür?

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

kullanılmış komut dosyası: -

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

Her şeyden önce, bir çift var; '' İhtiyacınız olan yerde '+' - Kodunuzu yanlış kopyaladığınızı var sayıyorum? – egrunin

+0

Çok teşekkürler ... Sorgum aşağıdaki gibi değişti, ancak yine de aynı hatayı alıyorum :( – user513655

+0

Komut dosyası: - "PriceHistory.UnitSellRate öğesini seçin," + "PriceHistory.DateAssigned, PriceHistory.DateChanged, PriceHistory.MRP, PriceHistory.ProductOffer "+ "productPrice dan" + "iç PriceHistory.UnitPriceId = ProductPrice.UnitPriceId üzerinde PriceHistory katıl" + "iç prdc.prdcID = ProductPrice.PrdcId üzerinde Prdc katıl" + " sol Suppliers.supplierId = Ürünleri Tedarikçi katılmak. SupplierId "+ " Burada Products.ProductCode = '"+ productCode +"' "; – user513655

cevap

1

Eğer tırnak bitmeden bir yere ihtiyacınız

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

dize sql =" select FiyatHistory.UnitSellRate, "+" PriceHistory.DateAssigned, PriceHistory.DateChanged, PriceHistory.MRP, PriceHistory.ProductOffer "+ "productPrice den" + + "iç PriceHistory.UnitPriceId = ProductPrice.UnitPriceId üzerinde PriceHistory birleştirme", "iç prdc.prdcID = ProductPrice.PrdcId üzerinde Prdc birleştirme" + "sol Suppliers.supplierId = Products.SupplierId üzerinde Tedarikçi birleştirme" + "Products.ProductCode =" "+ productCode +" '"; – user513655

+0

Yukarıdaki değiştirilen betikle aynı hatayı aldım :( – user513655

+0

Hala aynı hatayı alıyoruz .. FiyatHistory.UnitSellRate, PriceHistory.DateAssigned, PriceHistory.DateChanged, PriceHistory.MRP, PriceHistory.ÜrünOyundan FiyatÜrüne katılarak fiyatlandırınÜcretli fiyatHistory.UnitPriceId = ProductPrice Prdc.prdcID = ProductPrice.PrdcId, Prdc.prdcID = ProductPrice.PrdcId öğesinin solundaki Prdc'ye katılmayı sağladı. Prdc.ProductCode = 'df' – user513655

1

de elimden iki temel sorun var gibi bkz. (zaten tanımlanmış boşluk ve noktalı virgül sorunları dışında):

1 - Access/Jet, birden fazla birleştirmeyi gerçekleştirirken parantez gerektirir. Temel olarak, aslında sadece bir seferde iki tablo birleştirme sağlamak üzere alt sorgular telafi etmek gerekir, bu nedenle bunun yerine:

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 

... iç parantez içinde katılır şu ikisini birleşim oluşturmak için sarmak gerekiyor sonra böyle vb birine daha çoğuna eşlik edecek birine tablolar,:

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 - Görüyorum ki SOL JOIN ile sonunda katılmadan şeye gerçekten emin değilim. Bu LEFT JOIN, Suppliers ve Products tablolarına katılmaya çalışıyor, ancak bunların hiçbiri zaten yaptığınız INNER JOINs'teki hiçbir şeyle herhangi bir bağlantıya sahip görünmüyor. Prdc ve Ürünlerin aynı masa olması mümkün mü?

+0

hala gitmek için bir yer olacağını varsayalım ... yardım takdir edilecektir. – user513655

+0

Bu aynı sorunu yaşıyordu ve tabloyu sarma ve parantez içinde ilk iç birleştirme benim için çalıştı! –

İlgili konular