Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Report Builder Same Key has already been added; Update with Cte

I have declared a table with the following variables:

CREATE TABLE #tmp
(
    [Counter] int              
    ,Period Date primary key
    ,VanMe float
)

And I have done some steps to set the VanMe.

The following is the With and the Select statement where the error is occurring:

I narrowed this down to the first part in With because for Report Builder cte.Period and #tmp.Period is considered the same two keys. After I changed that and used the Select statement it still gave me the same error.

Is there a way I can calculate the Avg in the With statement and just call

Select * from #tmp. 

I tried it with the update it did not work at all. It gave me null for the VanMeAvg and the other Avg variables.

Please HELP!

The error that I get is this:

An item with the same key has already been added.
like image 524
Masa Rumi Avatar asked Mar 22 '13 16:03

Masa Rumi


People also ask

How do I add a query to report builder?

Open the query designer. In the Report Data pane, right-click the dataset, and then click Query. The query designer that is associated with the data source opens. In the Database view pane, expand the folders that display a hierarchical view of database schema objects such as tables, views, and stored procedures.

How do I enable Report Builder?

From Setup, enter Reports in the Quick Find box, then select Reports and Dashboards Settings. Check Enable Lightning Report Builder (Beta). Review the Report Builder Upgrade section of the page and click Enable.

What is Report Builder in SQL?

An SQL report builder is a software solution that enables technical and non-technical users to create and generate a variety of interactive reports from a set of relational databases.


1 Answers

It seems that there are 2 columns with the same name in the select query .Column names should be distinct . The repeated columns are

HfxMetric
,HfxMetric = AVG(HfxMetric) Over (Partition by [Counter])
like image 88
praveen Avatar answered Sep 22 '22 22:09

praveen