SQL Server 2008, how to update a column with seeded random values? -


i've found lot of answers call rand being reseeded, means while different values created each row, operation cannot repeated same result. there way ensure each row gets new value still seeded initial call?

the below attempts don't work:

update #testtable set     number = convert(int, floor(rand(checksum(newid())) * 1000)) 

every row has different value, every time run values given row changed.

declare @randomseeder float;  --seeds value, better way this. select @randomseeder = rand(5336);   update #testtable set     number = convert(int, floor(rand() * 1000)); 

it appears rand called once , value used in every row.

to put guid column value should declare example:

[number] uniqueidentifier constraint [df_email_emailid] default (newsequentialid()) not null

you use value generate random number.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -