mercredi 4 octobre 2017

Updating multiple row with random data from another table?

Combining some examples, I came up with the following query (fields and table names have been anonymised soI hope I didn't insert typos).

UPDATE destinationTable
SET destinationField = t2.value
FROM destinationTable t1
CROSS APPLY (
    SELECT TOP 1 'RequiredPrefix' + sourceField as value
    FROM #sourceTable
    WHERE sourceField <> ''
    ORDER BY NEWID()
    ) t2

Problem Currently, all records get the same value into destinationField , value needs to be random and different. I'm probably missing something here.




Aucun commentaire:

Enregistrer un commentaire