Hi everybody,
I am working on an SSIS project, one step of which involves using T-SQL to create a temporary table in SQL Server, join it to other tables in the database (based on a series of person identifiers which are unique in combination), get the GUID that is assigned to that person in our database, and then update the temp table with those GUIDs.
After that, if the person does not exist in our database, I want to simply assign a NewId() to the GUID column in my temp table. This will allow me to do subsequent inserts and updates on a series of related tables using set logic (as opposed to loops or cursors, which we are trying to avoid).
So far, that's pretty straightforward, but the data in the temp table isn't that simple: one person may have more than one row. For example, while the identifier columns for a single person will always be the same, they may have more than one value for some non-identifying column (let's say "hobby").
So, if one person has more than one hobby, they will have as many rows as they have hobbies, and those rows will be identical except for the value in the "hobby" column.
I discovered today that I cannot use an UPDATE statement with the GROUP BY clause. So my question is, how can I do a set logic UPDATE statement that will add a new GUID for each person (where the GUID column is currently null) and ensure that the same GUID is assigned to each person regardless of how many rows ("hobbies") they have.
Thanks for any suggestions or guidance!
Dylan