I've got "one last hurdle" on a project.
Background:
1) User creates/modifies a few rows of data in "TableA" in Database A.
2) I round up the data, use BCP and a Format file to export it.
3) Database B imports the subset of data into a temp table "t_TableA"
4) Since Database B has a different schema, I modify the structure of
the temp table to match the target table and ensure the data conforms
to rules for nulls, minimum values, etc.
That part is all done.
Problem:
I can't just delete/insert the rows in the target table (cascading deletes
will cause some real damage. I want to iterate through the temp table "t_TableA".
I know its Primary Key(s).
If the row doesn't exist, it is easy to do a
Insert Into TableA Select(F1, F2, ...)
Select F1, F2, F3, ... From t_TableA
If the row does exist, I can make an Update statement enumerating
the columns to update.
The problem is how does one define a Cursor in T-SQL when none of
the info is known until run-time (table name, PKs, etc.)?
How do I iterate through the temp table?
Thanks,
Wayne
Background:
1) User creates/modifies a few rows of data in "TableA" in Database A.
2) I round up the data, use BCP and a Format file to export it.
3) Database B imports the subset of data into a temp table "t_TableA"
4) Since Database B has a different schema, I modify the structure of
the temp table to match the target table and ensure the data conforms
to rules for nulls, minimum values, etc.
That part is all done.
Problem:
I can't just delete/insert the rows in the target table (cascading deletes
will cause some real damage. I want to iterate through the temp table "t_TableA".
I know its Primary Key(s).
If the row doesn't exist, it is easy to do a
Insert Into TableA Select(F1, F2, ...)
Select F1, F2, F3, ... From t_TableA
If the row does exist, I can make an Update statement enumerating
the columns to update.
The problem is how does one define a Cursor in T-SQL when none of
the info is known until run-time (table name, PKs, etc.)?
How do I iterate through the temp table?
Thanks,
Wayne