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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 generate a random number

Author  Topic 

verybrightstar
Starting Member

16 Posts

Posted - 2006-06-06 : 21:27:53
hi all,

i have a table called Order , the total no of total items in the Order table is 8000

how can i create a random number from 1 - 8000 to insert into the temp table


declare @count as int
select @count = count(*) from Order
print @count

create table #temp1 (id int , RNID int)
select CAST(Rand() * @count as int) as rnd from Order insert into #temp1

select * from #temp1

drop table #temp1

kt

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-06-06 : 21:39:54
[code]insert into #temp1(id, RNID)
select id, (abs(convert(int, convert(varbinary, newid()))) % 8000) + 1
from Order[/code]


KH

Go to Top of Page

verybrightstar
Starting Member

16 Posts

Posted - 2006-06-06 : 22:28:54
ok thanks

quote:
Originally posted by khtan

insert into #temp1(id, RNID)
select id, (abs(convert(int, convert(varbinary, newid()))) % 8000) + 1
from Order



KH





kt
Go to Top of Page
   

- Advertisement -