Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Duplicate Attribute Name in HANA procedure

Hi,

I'm a beginner and just wanted to ask a basic question.

I have two tables

  1. Employee (emp_id, emp_name, emp_grp, salary, level, skill)
  2. Bonus (skill, level, bonus)

in my procedure I'm joining these two table and storing in variable.

I'm getting Duplicate attribute name error.

I assume this is because I had skill and level as common name in both tables.

After changing the column names in Bonus table to B_SKILL and B_LEVEL, issue was resolved.

But I believe there has to be a better way to fix this because changing the column name will not be feasible every time.

Tags:
Former Member
replied

Hello

There is indeed a solution to this - explicitly listing the columns you require, and column aliases.

You haven't showed SQL, however I guess it is something like this

select

  *

from

  employee, bonus

where

  employee.skill = bonus.skill and employee.level = employee.level

This won't work as the column skill exists in both tables, and using * isn't a good idea anywhere except when messing about.  The easiest solution would be to explicitly list the columns in the select clause as below (I added a table alias too, you know, just for fun).  There's no need to pull the skill column twice, as it will have the same value in this case

select

  e.emp_id, e.skill, e.level, b.bonus

from

  employee e, bonus b

where

  e.skill = b.skill and e.level = b.level


In some cases you might want the values from both skill columns (an outer join for example), then in which case you can alias the columns, as below


select

  e.emp_id, e.skill as emp_skill, b.skill as bonus_skill, e.level, b.bonus

from

  employee e, bonus b


Michael

1 View this answer in context
Not what you were looking for? View more on this topic or Ask a question