2010-10-12 50 views
17

當我嘗試在SSRS IDE中設置數據集時,出現快照中顯示的錯誤。「具有相同密鑰的項目已添加」SSRS嘗試設置數據集時出錯

該查詢在SQL Server Management Studio中完全正常,我在想我哪裏出錯了?!

與DB的連接已經建立。

alt text


可選:

如果你想看看我的查詢(它太長),我檢查非常好。沒有錯:

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 

回答

36

在格式化您的腳本後,我注意到有2列與您選擇的名稱相同。確保更改最終名稱&,在Management Studio中運行語句時,每列都有一個唯一名稱。

話雖這麼說,兩列,我注意到有重複的名字是customerquoteproducts.istaxpaidcustomershipping.istaxpaid

我希望幫助!

+0

我明白,但這些相似列駐留在完全不同的表!我提到了前綴,所以系統不應該感到困惑......感謝您的幫助,我會檢查出來...... – 2010-10-12 06:02:28

+0

已解決............. – 2010-10-12 08:17:46

+0

是的,另一個瘋狂的,在Microsoft BI中無用的錯誤...我也有同樣的問題,這工作 – 2016-11-28 07:13:32

0

我今天遇到這個帖子,當我收到同樣的問題。 我的問題有史以來有點不同。

我在我的SP中有一個臨時表和If語句。 所以我的SP看起來是這樣的:

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 ... 

因此,爲了在SSRS「刷新」我的領域,我註釋掉If語句,並保持與我的字段名稱查詢之一。 剛把要記得添加一切恢復之後...

使用Visual Studio 2012/SQL 2012

相關問題