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.
| Author |
Topic |
|
kishoreg
Starting Member
11 Posts |
Posted - 2010-02-24 : 04:54:25
|
| Hi,I have two columns Col1, Col2 and both contains same data. Now i want to shuffle(Reorder) the rows in Col2 and the rows in Col1 should be unchanged.Please let me know the query for this. |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-02-24 : 04:57:46
|
| Do you need this?select Col1, Col2 from table_name order by newid()Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-24 : 05:00:21
|
| Post some sample data with expected resultMadhivananFailing to plan is Planning to fail |
 |
|
|
kishoreg
Starting Member
11 Posts |
Posted - 2010-02-24 : 05:04:38
|
| Original TableCol1 col21 12 23 34 45 5Result Col1 Col21 42 13 54 25 1 I want col2 to be shuffled. The col's doesn't have any pk's. |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-02-24 : 05:14:29
|
quote: Originally posted by kishoreg Original TableCol1 col21 12 23 34 45 5Result Col1 Col21 42 13 54 25 1 I want col2 to be shuffled. The col's doesn't have any pk's.
Do you want the columns sorted this way?Result Col1 Col21 52 43 34 25 1 PBUH |
 |
|
|
kishoreg
Starting Member
11 Posts |
Posted - 2010-02-24 : 05:17:46
|
| I want Col2 to be shuffled in any way, except ascending & descending order. |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-02-24 : 05:22:12
|
| [code]select * from (select 1 union allselect 2 union allselect 3 union allselect 4 union allselect 5 )t(x) order by NEWID()[/code]PBUH |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-24 : 05:33:15
|
| Try thisselect t1.col1,t2.col2 from(select row_number() over(order by col1) as sno,col1 from table1) as t1inner join(select row_number() over(order by newid()) as sno,col2 from table1) as t2 on t1.sno=t2.snoMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|