select au_id,cast( null as float) as rnd into #RndAuthors
from Authors(TABLOCK SERIALIZABLE)
--SELECT * FROM #RndAuthors
create clustered index idx_ci_au_id on #RndAuthors(au_id)
declare @key as varchar(11)
select @key=min(au_id) from #RndAuthors
/*create a loop that iterates through all the key values,and
for each key,invokes the RAND() function with no input,update
the float column with the random value generated.*/
while @key is not null
begin
update #RndAuthors set rnd=rand() where au_id=@key
select @key=min(au_id) from #RndAuthors where au_id>@key
end
--select * from #RndAuthors
set rowcount 10
select a.* from authors as a join #RndAuthors as R
on a.au_id=R.au_id
order by rnd
declare @conut int,@IdStr varchar (8000),@intX int ,@ShoeCount int
select @ShoeCount=20
select @conut=(select count(*) from Table)
drop table #table1
select IDENTITY(int,1, 1) as iid,*
into #table1
from Table
select @intX=0
while @intX<@ShoeCount
Begin
select @IdStr=@IdStr+''''+cast(cast(rand()*@conut as int)as varchar)+''''
select @intX=@intX+1
if @intX<@ShoeCount select @IdStr=@IdStr+','
End
select top 200 IDENTITY(int,1,1) as rid,* into #jr from yourtable
declare @rindex int
set @rindex= ceiling( rand()*10)
select top 10 * from #jr where rid % @rindex =0
drop table #jr