Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have a mapping table that uses a non unique attribute. I need a way to map that attribute to one of the attributes it is referring too, to get the unique attribute. Here is an example of what i am trying to do:

I was thinking my best bet would be to write an aggregate function, but CLR is not an option right now. Rebuilding the relationship is not an option either, as we are stealing it from another database so the pk doesn't map, only the name.
The only thing that is working is doing it in a cursor, which unsurprisingly is slow enough that I have to get it set-wise.

EDIT:

If there are multiple entries of TABLE1, then this will breakdown. For instance if we use this for TABLE1_TABLE2 instead (notice that we had to keep the old, no longer valid pk):

1 Answer
1

This will work with the sample data you have provided here. Your data could be entered into your tables in a way so that this will not work. If that is the case, please update your question with data that will show the issues you have.