2010-10-12 12 views
17

Veri kümesini SSRS IDE'ye ayarlamaya çalıştığımda, anlık görüntüde gördüğünüz hatayı alıyorum."Aynı anahtarla bir öğe zaten eklendi" Veritabanını Ayarlamaya Çalışırken SSRS'de Hata

Sorgu, SQL Server Management Studio'da tamamen düzgün çalışıyor, nerede hata yaptım acaba ?!

DB ile bağlantı kurulmuş. İSTEĞE


alt text

: durumunda

uygun (çok uzun) benim sorguda bir göz istiyorum, ben çok iyi kontrol etti. İçinde yanlış bir şey:

SELECT Customer.customerID, Customer.companyName, CustomerInvoice.dueDate, CustomerInvoice.cuInvoiceID, CustomerQuote.PONumber, Product.productName, CASE WHEN (SELECT  isTaxPaid 
                FROM   SupplierQuoteProducts 
                WHERE  productID = CustomerQuoteProducts.ProductID) = 1 THEN CustomerQuoteProducts.unitPrice * 1.15 
                WHEN (SELECT  isTaxPaid 
                FROM   SupplierQuoteProducts 
                WHERE  productID = CustomerQuoteProducts.ProductID) = 0 THEN CustomerQuoteProducts.unitPrice 
                ELSE CustomerQuoteProducts.unitPrice 
                END AS "unitPrice", 
         CustomerQuoteProducts.qty, CustomerQuoteProducts.isTaxPaid, PaymentMethod.paymMethDesc, CustomerInvoice.customerQuoteID, CustomerInvDetail.paidDate, CustomerInvDetail.clearedDate, 
         CustomerInvDetail.notes, CustomerInvDetail.sentDate, PaymentExpected.payExpectedTitle, PaymentStatus.paymentStatusTitle, 
CASE WHEN 
(SELECT  isTaxPaid 
FROM   SupplierQuoteProducts 
WHERE  productID = CustomerQuoteProducts.ProductID) = 1 AND CustomerQuoteProducts.qty > 0 AND 
CustomerQuoteProducts.isTaxPaid > 0 THEN (((CustomerQuoteProducts.unitPrice * 1.15) * 1.15) * CustomerQuoteProducts.qty) WHEN 
(SELECT  isTaxPaid 
FROM   SupplierQuoteProducts 
WHERE  productID = CustomerQuoteProducts.ProductID) = 1 AND CustomerQuoteProducts.qty <= 0 AND 
CustomerQuoteProducts.isTaxPaid > 0 THEN ((CustomerQuoteProducts.unitPrice * 1.15) * 1.15) WHEN 
(SELECT  isTaxPaid 
FROM   SupplierQuoteProducts 
WHERE  productID = CustomerQuoteProducts.ProductID) = 0 AND CustomerQuoteProducts.qty > 0 AND 
CustomerQuoteProducts.isTaxPaid > 0 THEN ((CustomerQuoteProducts.unitPrice * CustomerQuoteProducts.qty) * 1.15) WHEN 
(SELECT  isTaxPaid 
FROM   SupplierQuoteProducts 
WHERE  productID = CustomerQuoteProducts.ProductID) = 0 AND CustomerQuoteProducts.qty <= 0 AND 
CustomerQuoteProducts.isTaxPaid > 0 THEN (CustomerQuoteProducts.unitPrice * 1.15) WHEN 
(SELECT  Count(isTaxPaid) 
FROM   SupplierQuoteProducts 
WHERE  productID = CustomerQuoteProducts.ProductID) = 0 AND CustomerQuoteProducts.qty > 0 AND 
CustomerQuoteProducts.isTaxPaid > 0 THEN ((CustomerQuoteProducts.unitPrice * 1.15) * CustomerQuoteProducts.qty) WHEN 
(SELECT  Count(isTaxPaid) 
FROM   SupplierQuoteProducts 
WHERE  productID = CustomerQuoteProducts.ProductID) = 0 AND CustomerQuoteProducts.qty <= 0 AND 
CustomerQuoteProducts.isTaxPaid > 0 THEN (CustomerQuoteProducts.unitPrice * 1.15) WHEN 
(SELECT  isTaxPaid 
FROM   SupplierQuoteProducts 
WHERE  productID = CustomerQuoteProducts.ProductID) = 1 AND CustomerQuoteProducts.qty > 0 AND 
CustomerQuoteProducts.isTaxPaid <= 0 THEN (((CustomerQuoteProducts.unitPrice * 1.15)) * CustomerQuoteProducts.qty) WHEN 
(SELECT  isTaxPaid 
FROM   SupplierQuoteProducts 
WHERE  productID = CustomerQuoteProducts.ProductID) = 1 AND CustomerQuoteProducts.qty <= 0 AND 
CustomerQuoteProducts.isTaxPaid <= 0 THEN ((CustomerQuoteProducts.unitPrice * 1.15)) WHEN 
(SELECT  isTaxPaid 
FROM   SupplierQuoteProducts 
WHERE  productID = CustomerQuoteProducts.ProductID) = 0 AND CustomerQuoteProducts.qty > 0 AND 
CustomerQuoteProducts.isTaxPaid <= 0 THEN ((CustomerQuoteProducts.unitPrice * CustomerQuoteProducts.qty)) WHEN 
(SELECT  isTaxPaid 
FROM   SupplierQuoteProducts 
WHERE  productID = CustomerQuoteProducts.ProductID) = 0 AND CustomerQuoteProducts.qty <= 0 AND 
CustomerQuoteProducts.isTaxPaid <= 0 THEN (CustomerQuoteProducts.unitPrice) WHEN 
(SELECT  Count(isTaxPaid) 
FROM   SupplierQuoteProducts 
WHERE  productID = CustomerQuoteProducts.ProductID) = 0 AND CustomerQuoteProducts.qty > 0 AND 
CustomerQuoteProducts.isTaxPaid <= 0 THEN ((CustomerQuoteProducts.unitPrice * CustomerQuoteProducts.qty)) WHEN 
(SELECT  Count(isTaxPaid) 
FROM   SupplierQuoteProducts 
WHERE  productID = CustomerQuoteProducts.ProductID) = 0 AND CustomerQuoteProducts.qty <= 0 AND 
CustomerQuoteProducts.isTaxPaid <= 0 THEN (CustomerQuoteProducts.unitPrice) END AS [TotalPrice], CASE WHEN row_number() OVER (partition BY 
CustomerInvoice.cuInvoiceId 
ORDER BY newid()) = 1 THEN (CASE WHEN CustomerShipping.isTaxPaid > 0 THEN (CustomerShipping.shippingPrice * 1.15) 
WHEN CustomerShipping.isTaxPaid <= 0 THEN (CustomerShipping.shippingPrice) END) END AS [ShippingCost], 
CASE WHEN row_number() OVER (partition BY 
CustomerInvoice.cuInvoiceId 
ORDER BY newid()) = 1 THEN (CASE WHEN CustomerShipping.isTaxPaidForOrigPr > 0 THEN (CustomerShipping.origShipPrice * 1.15) 
WHEN CustomerShipping.isTaxPaidForOrigPr <= 0 THEN (CustomerShipping.origShipPrice) END) END AS [ShippingOrigCost], 
CustomerShipping.isTaxPaid, 
CustomerShipping.isTaxPaidForOrigPr, 
CustomerShipping.shippingDate, CustomerShipping.trackingNumber, ShippingMethod.shippingVia, CustomerShipping.desAddress, 
CustomerShipping.desCity, CustomerShipping.desPOBox, CustomerShipping.desPostalCode, CustomerShipping.desProvince, CustomerShipping.descName, 
CustomerShipping.packageContent, CustomerShipping.cuShippingID, Country.countryName, CustomerShipping.packageDepth, 
CustomerShipping.packageHeight, CustomerShipping.packageWeight, CustomerShipping.packageWidth, CustomerShipping.pickUpLocation 
FROM   CustomerInvoice INNER JOIN 
         CustomerInvDetail ON CustomerInvoice.cuInvoiceID = CustomerInvDetail.cuInvoiceID INNER JOIN 
         CustomerQuote ON CustomerQuote.CustomerQuoteID = CustomerInvoice.CustomerQuoteID INNER JOIN 
         CustomerQuoteProducts ON CustomerQuoteProducts.CustomerQuoteID = CustomerQuote.CustomerQuoteID INNER JOIN 
         CustomerShipping ON CustomerShipping.CustomerQuoteID = CustomerInvoice.CustomerQuoteID INNER JOIN 
         PaymentStatus ON PaymentStatus.paymentStatusID = CustomerInvDetail.paymentStatusID INNER JOIN 
         Customer ON Customer.CustomerID = CustomerQuote.CustomerID INNER JOIN 
         Product ON CustomerQuoteProducts.productID = Product.productID INNER JOIN 
         Country ON Country.countryID = CustomerShipping.countryID INNER JOIN 
         ShippingMethod ON ShippingMethod.shippingMethodID = CustomerShipping.shippingMethodID INNER JOIN 
         PaymentExpected ON PaymentExpected.paymentExpectedID = CustomerInvDetail.paymentExpectedID INNER JOIN 
         PaymentMethod ON PaymentMethod.paymentMethodID = CustomerInvoice.paymentMethodID 
WHERE CustomerInvoice.cuInvoiceID = @cuInvID 

cevap

36

senaryonuz biraz biçimlendirme sonra, seni seçerek aynı isimde 2 sütun olduğunu fark ettim. & adının son halini değiştirdiğinizde, Management Studio'da ifadenizi çalıştırdığınızda her sütunun bir benzersiz adı vardır. söyleniyor

, ben fark iki sütun var yinelenen adları customerquoteproducts.istaxpaid ve O yardımcı olur umarım

customershipping.istaxpaid vardır!

+0

2012 kullanarak ...

geri sonradan her şeyi eklemeyi hatırlamak zorunda kaldı, ama bu benzer sütunlar tamamen farklı tablolarda ikamet! Ben önek bahsetti, bu yüzden sistem karışmamalı ... Yardımlarınız için teşekkürler, ben kontrol edecek ... –

+0

SOLVED .............. –

+0

evet, başka bir deli, Microsoft BI'da yardımcı olmayan hata ... Aynı problemi de yaşadım ve bu işe yaradı –

0

Aynı sorunu aldığımda bugün bu yazıya rastladım. Sorunum, nasıl biraz farklıydı.

SP'mde geçici bir tablo ve If ifadesi vardı.

DECLARE @myCheck as int 
SET @myCheck = 0 

SELECT @myCheck = CASE WHEN [checkfield] = 'xxx' then 1 else 0 end 
    FROM checktable 
    WHERE ... 


SELECT myfields.* 
into #temptable 
FROM mytable 
WHERE ... 


IF @myCheck = 1  --if ssrs does'nt want ot refresh your fields, remove hte if as it does not see past this... 
    select * 
    FROM #temptable 
     LEFT JOIN tableA 
      ON ... 
ELSE 
    select * 
    FROM #temptable 
     LEFT JOIN tableB 
      ON ... 

Yani SSRS benim alanları "yenilemek" için, ben ise deyimi dışarı yorumladı ve alan adları ile benim sorgulardan birini tuttu: Yani benim SP böyle bir şey görünüyordu. Sadece Visual Studio 2012/SQL görüyorum