Eton B.
Eton B.

Reputation: 6281

Updating a column with random values between specific range?

I have a column where I need to update it's value by random numbers between 1 and 3150 (just being specific)

Can I do this with a simple TSQL statement?

Upvotes: 0

Views: 1915

Answers (1)

Phil Hunt
Phil Hunt

Reputation: 8521

Use RAND(), re-seeding the function on each call.

UPDATE MyTable
SET MyColumn = 1 + FLOOR(3150 * RAND(CONVERT(varbinary, NEWID())))
WHERE ...

Upvotes: 2

Related Questions