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
 General SQL Server Forums
 New to SQL Server Programming
 Query Help. Thanks

Author  Topic 

mavershang
Posting Yak Master

111 Posts

Posted - 2010-04-27 : 17:48:50
Hi there. I have a problem with randomizing a column. Here is my question.

The original table contains
Marker Col1 Col2
1 A C
2 A A
3 B D
...

I want to randomize Col1 and get a temporary table like
Col1 Col2
A A
B C
.....
This table will be used to calculate some statistic value. Because this randomization step need to be repeated over 10^6 times, temporary table created in the intermediate step might not be efficient enough.

Could anyone help me out? Thanks

hanbingl
Aged Yak Warrior

652 Posts

Posted - 2010-04-27 : 18:24:53
Looks like your Col2 is sorted.

SELECT * FROM TAB order by COL2, NEWID()
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-28 : 05:57:52
how did B got associated to C? you dont have such a record in your sample?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -