Skip to content
Advertisement

Seed Data using merge statement including data from external table

I’ve been provided an excel file with data that I am supposed to merge into a database. From this data I am concatinating a string in this format:

'Maastricht' here is the name of a city, which I need up in a foreign table during the insert. This is the script that I have come up with:

To Replace the city name with the actual foreign key I tried to simply do a select from the location table, which unfortunately only ever gives me the first Id it does find, which results in wrong relationships.

What is the correct way to lookup the foreign-key for a city name, so it does insert the correct value during the insert?

Advertisement

Answer

You can join the locations table to the values like this:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement