Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Sam Vanga

Sam Vanga helps business people solve their data problems and enables them make data-driven-decisions. His specialties include data integration, data warehouse and database development, and BI design. Sam blogs at http://SamuelVanga.com.

#SSRS error – An item with the same key has already been added

Here is a simple yet annoying error I ran into while creating a dataset. Below is the query that I was using and it would run just fine when executed from management studio.

SELECT
CalendarYear Yr
, CalendarMonthNum Mth
, CalendarMonthName Mth
FROM
dbo.Orders o

But SSRS doesn’t like those two columns with the same name “Mth” resulting in the error “an item with the same key has already been added”.
To resolve this simply make sure that no two columns in your dataset have the same name.

~Sam


Comments

Posted by dlchase on 16 November 2011

Why would you do this?  Does not seem to be a good practice whether it works or not.

Posted by jcrawf02 on 16 November 2011

Happens to me sometimes accidentally, same column names in different tables that I forgot to alias, so the result has two of the same. Think the above example probably doesn't happen as often, but it's a good demonstration of the problem.

Posted by JD on 16 November 2011

I've encountered this error before also.  In my case, the duplicate column names were a mistake.

If SQL Server allows it, SSRS should handle it - preferably by an informative error message.

(I'm suprised SQL Server allows it - I can't think of a good reason why anyone would want to do it on purpose.)

Posted by Samuel Vanga on 16 November 2011

Agreed. Not a good practice.

But I've encountered this several times. Specially while creating reports involving date information from a datetime column. I would pull both Month Number and Month Name. Month Name is shoed in the report and Month Number is used for sorting.

And accidently give the same alias name resulting in the above error.

~Sam.

Posted by Anonymous on 16 November 2011

Pingback from  #SSRS error ??? An item with the same key has... | SQL Server | Syngu

Leave a Comment

Please register or log in to leave a comment.