I'm working on a script to anonymize a table with patient data. I generated a table containing 50,000 rows of anonymous data.
What I need is a number of columns in the patient table to be updated with data from the generated table.
Ofcourse I already read about updating tabels and how to select random row from another table. What I can't figure out is how to combine this in one query.
I've seen CTE as a possible solution, but I don't understand how it works. One of the main issues I have is that the generated table doesn't have any key in it and even if it did it shouldn't be relevant since I just want to iterate ALL rows of the patient table updating its values with a random row from the generated table.
I have the following:
Update Patients
Set Patients.pat_FirstName = fn.GivenName,
pat_LastName = fn.SurName,
pat_StreetName = fn.StreetAddress,
pat_PostalCode = fn.ZipCode,
pat_City = fn.City,
pat_DateOfBirth = fn.BirthDay,
from
( Select Top 1,
GivenName,
SurName,
StreetAddress,
ZipCode,
City,
Birthday
from FakeNameGenerator tablesample(1000 rows)) as fn
but that executes the 'random' only once fill every row in the patient table with the same values. Like I said before, it can be (should be??) solved with CTE (tally?) tables, but how?
I'm close to grabbing C# and just code the darn thing...