2010-10-12 18 views
17

Cuando intento establecer el conjunto de datos en SSRS IDE, aparece el error que aparece en la instantánea."Ya se ha agregado un elemento con la misma clave" Error en SSRS al intentar establecer el conjunto de datos

La consulta funciona totalmente bien en SQL Server Management Studio, me pregunto dónde me salió mal?

La conexión a DB está bien establecida.

alt text


OPCIONAL:

En caso de que quiera echar un vistazo a mi consulta (es demasiado largo), he comprobado muy bien. No hay nada malo en ella:

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 

Respuesta

36

Después de formatear su guión un poco, me di cuenta de que hay 2 columnas con el mismo nombre que está seleccionando. Asegúrese de cambiar el nombre final & que cada columna cuando ejecuta su extracto en Management Studio tiene un único nombre.

Dicho esto, las dos columnas que noté tienen nombres duplicados son customerquoteproducts.istaxpaid y customershipping.istaxpaid

espero que ayude!

+0

veo, pero estas columnas similares residen en totalmente diferentes mesas! Menciono el prefijo, por lo que el sistema no debe confundirse ... Gracias por su ayuda, lo comprobaré ... –

+0

SOLUCIONADO ............. –

+0

sí, otro loco, error inútil en Microsoft BI ... También tuve el mismo problema y esto funcionó –

0

Me encontré con esta publicación hoy cuando recibí el mismo problema. Mi problema sin embargo fue un poco diferente.

Tenía una tabla temporal y una declaración If en mi SP. Así que mi SP parecía algo como esto:

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

Así que con el fin de "refrescar" mis campos en SSRS, comenté a cabo la instrucción If y se mantiene una de mis consultas con los nombres de campo. sólo tenía que acordarse de añadir todo de nuevo después ...

mediante Visual Studio 2012/SQL 2012

Cuestiones relacionadas