Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 randomising the value of a field for all rows?

Author  Topic 

indieman
Starting Member

12 Posts

Posted - 2006-04-13 : 18:56:41
i have some test data that i need to insert into a table. there needs to be about a 1000 rows so obviously i dont want to manually do it.

what i need to randomise is the value of one field.. Consultant_Ability

I already have 1000 rows that have the ConsultantID number, i just need to make the Consultant_Ability random.

at the moment i have
ConsultantID...Consultant_Ability
1..............1
2..............1
3..............1
4..............1
5..............1

can anyone help me create a statement that will go through all the ConsultantID numbers and randomise the Consultant_Ability between values 0 and 10?

many thanks,
ben

edit: needs to be an update state as i have other data in there too!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-04-13 : 19:16:34
[code]update yourtable
set Consultant_Ability = convert(int, convert(int, convert(varbinary(1), newid())) / 255.0 * 10)
[/code]



KH


Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-04-13 : 19:57:24
[code]
update MyTable
set
Consultant_Ability =
abs(convert(int,convert(varbinary(4),newid())))%11
[/code]

CODO ERGO SUM
Go to Top of Page

indieman
Starting Member

12 Posts

Posted - 2006-04-13 : 20:31:26
thanks for the "fast as ever" responses.

went with the one from khtan.

thanks guys
Go to Top of Page
   

- Advertisement -