Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Fix sql code : I get the error in SQL Report Builder \"An item with same key has

ID: 3869104 • Letter: F

Question

Fix sql code :

I get the error in SQL Report Builder "An item with same key has been added"

this is my sql query::


SELECT
   top 75 *
FROM  
    [EOLTData].[dbo].eolt_scenario_value v (NOLOCK)
    JOIN [EOLTData].[dbo].eolt_scenario o (NOLOCK) ON o.id = v.eolt_scenario_id
    JOIN [EOLTData].[dbo].eolt_sequence q (NOLOCK) ON q.id = o.eolt_sequence_id
    JOIN [EOLTData].[dbo].eolt_process p (NOLOCK) ON p.id = q.eolt_process_id
    JOIN [EOLTData].[dbo].eolt_stage g (NOLOCK) ON g.id = p.eolt_stage_id              

ORDER BY
    g.stage_start      

____________________________________________________

i would to to keep all coulmns but exclude id columns beside eolt_scenario_value v

Explanation / Answer

The issues comes when 2 columns with the same name are selected.

As you are doint SELECT top 75 * -> * might be causing selecting two or more columns with same name from different tables.

Instead of using "SELECT top 75 *" Select each individual columns you want. For eg:

SELECT v.eolt_scenario_id ...

Also to get top 75 records, you can use WHERE ROWNUM <= 75, This will give first 75 recods which is same as top 75 records

So query will be like :

SELECT

  g.stage_start ,  v.eolt_scenario_id , q.id <other columns you need>
FROM  
    [EOLTData].[dbo].eolt_scenario_value v (NOLOCK)
    JOIN [EOLTData].[dbo].eolt_scenario o (NOLOCK) ON o.id = v.eolt_scenario_id
    JOIN [EOLTData].[dbo].eolt_sequence q (NOLOCK) ON q.id = o.eolt_sequence_id
    JOIN [EOLTData].[dbo].eolt_process p (NOLOCK) ON p.id = q.eolt_process_id
    JOIN [EOLTData].[dbo].eolt_stage g (NOLOCK) ON g.id = p.eolt_stage_id              

WHERE

ROWNUM <= 75

ORDER BY
    g.stage_start ;

Please upvote if you found it useful.