partner1220
Weaksauce
- Joined
- Aug 22, 2008
- Messages
- 75
Hi,
I'm looking to write a dynamic update statement that reads from a table which I will load through an ETL tool. I'm not too comfortable with dynamic SQL.
Here's what I'm thinking from the source table:
Table_Name, Primary_Key, Field_Name, New_ValueCustomer, 123, First_Name, Bob
Address, 837, Line_1, 123 Main St
For example, the data above would generate and execute the following update statements:
UPDATE Customer SET First_name = 'Bob' WHERE Address_ID = 123
UPDATE Address SET Line_1 = '123 Main St' WHERE Customer_ID = 123
Now, the primary key gets tricky. 99% of the time, it is <TableName>_ID. Can I dynamically ID the primary key on the table? Otherwise, I can create another table that holds table/primary_key.
I'm looking to write a dynamic update statement that reads from a table which I will load through an ETL tool. I'm not too comfortable with dynamic SQL.
Here's what I'm thinking from the source table:
Table_Name, Primary_Key, Field_Name, New_ValueCustomer, 123, First_Name, Bob
Address, 837, Line_1, 123 Main St
For example, the data above would generate and execute the following update statements:
UPDATE Customer SET First_name = 'Bob' WHERE Address_ID = 123
UPDATE Address SET Line_1 = '123 Main St' WHERE Customer_ID = 123
Now, the primary key gets tricky. 99% of the time, it is <TableName>_ID. Can I dynamically ID the primary key on the table? Otherwise, I can create another table that holds table/primary_key.