web-dev-qa-db-fra.com

"Un élément avec la même clé a déjà été ajouté" Erreur sur SSRS lors de la tentative de définition du jeu de données

Lorsque j'essaie de définir le jeu de données dans SSRS IDE, j'obtiens l'erreur que vous voyez dans l'instantané.

La requête fonctionne parfaitement dans SQL Server Management Studio, je me demande où je me suis trompé?!

La connexion à la base de données est bien établie.

alt text


OPTIONNEL:

Au cas où vous voudriez regarder ma requête (c'est trop long), je l'ai très bien vérifiée. Rien de mal à ça:

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
18
Beginner_Pal

Après avoir un peu formaté votre script, j'ai remarqué qu'il y a 2 colonnes du même nom que vous sélectionnez. Assurez-vous de changer le nom final et que chaque colonne lorsque vous exécutez votre déclaration dans Management Studio a un nom unique .

Cela étant dit, les deux colonnes que j'ai remarquées portent des noms en double: customerquoteproducts.istaxpaid et customershipping.istaxpaid

J'espère que ça aide!

39
Amal Khezami

Je suis tombé sur ce message aujourd'hui quand j'ai reçu le même numéro. Mon problème était toutefois un peu différent.

J'avais une table temporaire et une instruction If dans mon SP. Ainsi, mon SP ressemblait à quelque chose comme ceci:

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

Donc, afin de "rafraîchir" mes champs dans SSRS, j'ai commenté la déclaration If et gardé une de mes requêtes avec les noms de champs. Je n'avais plus qu'à penser à tout rajouter par la suite ...

Utilisation de Visual Studio 2012/SQL 2012

0
adric