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
 Shuffling a specified set of column values

Author  Topic 

Yaserq8
Starting Member

2 Posts

Posted - 2013-12-25 : 04:55:03
Good afternoon,

I have a table @TempAnswers that looks like this:

QNo QA



1 A
1 B
1 C

2 A
2 B
2 C

3 A
3 B
3 C


I would like to shuffle QA randomly while keeping the same QNo in a stored procedure. So sort of shuffling QA grouped by QNo for the lack of a better term. I'd like to get something like this:

QNo QA



1 B
1 A
1 C

2 C
2 B
2 A

3 A
3 C
3 B

If anyone can help I would appreciate it.

Thank you for reading.

Regards

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-12-25 : 09:44:49
[code]select QNo, QA from @TempAnswers order by QNo, newid()[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Yaserq8
Starting Member

2 Posts

Posted - 2013-12-26 : 01:53:53
Thank you very much Khtan. That did it.

Go to Top of Page
   

- Advertisement -