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
 SQL Server Development (2000)
 Randomizing a column

Author  Topic 

SamC
White Water Yakist

3467 Posts

Posted - 2003-12-12 : 08:17:19
I want to shuffle the values in a column among all the rows.

Seems to me something using NEWID() and ORDER BY ought to be possible, but I'm left hanging


CREATE TABLE MyTable (
UserID INT ,
Firstname varchar(20) ,
Lastname varchar(20)
)

What's the easiest method to randomize Firstname among all the rows in MyTable?

Sam

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-12-12 : 08:21:08
you want to mix and match first and last names ?



Damian
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2003-12-12 : 08:36:43
Yep. I should have said earlier, I'd like it to be an UPDATE

UPDATE A
SET A.Firstname = .. random firstname

Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-12-12 : 08:41:27
You could modify this maybe ?
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=30723




Damian
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2003-12-12 : 08:57:29
Yes, that thread was one of the SQLTeam landmark solutions in my book. I actually discussed that solution with my lunch buddies who were not programmers. This just goes to show I was so impressed I was willing to bore others and risk losing friendship so I could recant the solution.

But this is a little different. And it feels like there should be a solution that doesn't require temp tables.
Go to Top of Page
   

- Advertisement -