I am trying to update a table with random values from a specific list of values. I got as far as the code below which does not work because the same value is being inserted into each row:
UPDATE [Post]
SET UserID = (
/** If I run this select statement independently then I get random value each time but not in this update statement **/
SELECT TOP (1) UserID
FROM
[User]
WHERE UserID IN (1,3,4,7)
ORDER BY NEWID()
)
WHERE
UserID <> 10 AND UserID <> 11
I tried looking at using ABS(CHECKSUM(NEWID()))%4 + 5
but generates any number between 1 and 4 which is not what I want. It has to be one of the values of 1,3,4,7
or any other list of specific values.