Generate random unique number through a webservice !

S

swethabilla

Hi all,

I am trying to auto generate a random 8-digit number to be populated
in a SQL server 2005 table . I am using a webservice written in C# to
do so.This autonumber will be further used in the infopath form( as
queried data).

The webservice needs to generate an random number for which I have
used in the Random() function. However I need to check back with the
previously filled entries to see if the random number produced does
not match the previous entries(need to be unique).

I can't find a way to write this query in the webservice.

Can anyone pls suggest me on this query (C#)?

Thanks in advance.
Swetha.
 
S

swethabilla

The used the following query which solved the issue,where
Random_unique is my column in the database.

select Random_unique from (select cast(abs(cast(cast(newid() as varbinary)as int))%100000000 +1 as char)as Random_unique) as d where Random_unique not in
(select Random_unique from foo) and len(Random_unique)=8 ;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top