Sorry, I got a little too quick on the trigger on the last response. If you actually LOOK at the output you'll see that the rand() function only fires once and that value is used in every record. The following really does work:
set nocount on
declare Random cursor for
select
empkey <-- the primary key for the emp table
from
emp
declare @empkey int
create table #RandomEmp (
random numeric(18,18),
empkey int
)
open Random
fetch next from Random into @empkey
while (@@fetch_status <> -1) begin
insert into #RandomEmp (random, empkey) values (rand(), @empkey)
fetch next from Random into @empkey
end
select
*
from
#RandomEmp r join emp e on r.empkey = e.empkey
order by
random
drop table #RandomEmp
close Random
deallocate Random