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
 SQL Server Development (2000)
 random query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-01-09 : 10:09:28
avital writes "i have a database with a table and 2 columns:
Phone Numbers nvarchar(13)
String nvarchar (50)

The phone numbers always start with +9725 and is followed by 7 other digits. I have to see many queries i can do on the database using a query of phone number that returns the string. however, the phone number i receive must be random so that each query returns a different number. how do i go about recieving this. this is what i tried to do but obviously it doesn't work:

use test
go



Declare @CurrentDate datetime
Declare @NextDate datetime
Declare @Count int
Declare @MaxValue nvarchar (50)
Declare @RandomNumber float
Set @Count=0
Set @currentDate=getdate()
Set @NextDate=dateadd(s,1,@CurrentDate)
select @maxvalue=max ([phoneNumber]) from test
select @randomnumber=rand() * @maxvalue
select @Currentdate as StartTime,@nextdate as EndTime,cast(@RandomNumber as nvarchar (50))

while @currentDate<@NextDate
begin
select string from test where [phoneNumber]=cast(@RandomNumber as nvarchar (50))

set @Count=@Count+1
set @CurrentDate =getdate()
end
select @Count as Total"
   

- Advertisement -