Insert Random Numbers for an Update statement

PHOTO EMBED

Tue Apr 12 2022 11:24:44 GMT+0000 (Coordinated Universal Time)

Saved by @paulbarry #vba

Declare @MinValueWanted int = 500,
  @MaxValueWanted int = 3000;
Select abs(cast(newid() as binary(6)) % (1 + 9006 - 9001)) + 9001;

USE OLIS_DATA_DEMO;

/************/
--24_StaffNumberOfPersonInjured
UPDATE [dbo].[AIRSData]
SET [24_StaffNumberOfPersonInjured] = abs(cast(newid() as binary(6)) % (1 + 9006 - 9001)) + 9001
WHERE [24_StaffNumberOfPersonInjured] =9004 
AND [AIRSID] > 54812
content_copyCOPY

Uses newid() instead of rand() as rand() will only select a random number once and apply it to all rows in the update, whereas newid() will give a different random number form the range to each row.