Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

random indentity

Status
Not open for further replies.

rexhunter

Programmer
Joined
Dec 30, 2004
Messages
9
Location
NL
In the user environment of Acces it is possible to set a counter to random. The engine produces random unique ID numbers. Is this also possible with SQL (TSQL) which works with the JET engine?

 
Not sure what you are looking for, but see if this will do.
SELECT NewID()
Have a Happy New Year.
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
First: happy new year (I've 6.5 hours to go in 2004).
In Acces you can choose:
Autogenerate number: *autoincrement (integer 32bit counter)
*random numbers (integer 32bit)

When you not use Acces, how can you perform this with e.g. create table on a JET 'server' or SQL server. It has to be JET compitable.
Making the table defenition with create table, with a column that has a unique random ID (32bit).
 
is this of any use ?
Code:
select cast(1e14 + rand() * (9e14-1) as bigint)

--Generates a random 15 digit number

select cast(1e13 + rand() * (9e13-1) as bigint)

--Generates a random 14 digit number

select cast(1e5 + rand() * (9e5-1) as bigint)

--Generates a random 6 digit number

And a Happy New Year to all !

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
Sorry, I don't want to generate a number with code, there fore I can use VB.NET. The only thing I want is that when I insert a new row, the server (JET) will automatically generate a unique random number for me.
I know that I can use the IDENTITY()/COUNTER(), but then I get a sequence of numbers, I don't want that. I want random numbers (preferably 32bit).
In the environment of Microsoft Access, this is possible. But I don't know how to do with SQL, that works with the JET engine.

E.G.
CREATE TABLE customers
(
uniqueid integer COUNTER(x,y) <-- this will give a sequence of numbers.
)

I want the same sample, but with random numbers (compatible with JET engine v4).

I appreciate your answers, but it's not the right. I hope that I've written my question good.

Just 5 hours and 10 minutes to go in 2004, in advance: happy new year, I hope you can make me happy in this year ;)
 
sorry cant help you any further - sure someone will be able to - anyway with only 5 hours 10 minutes to go till new year (it is 6.50PM) get yourself home and enjoy the new year. Solve this one next year - bet there will be someone who will help you by the end of the first day of 2005.

HNY !

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
Have you tried a GUID field? Datatype in SQL Server is uniqueidentifier. Tehn set the default value as newid()

Access will recognize this datatype as a replication id.

Questions about posting. See faq183-874
 
donutman kind of gave you the answer in the first post after your question...
 
Thank you all,
I tried this with SQL server 2000 and it worked perfectly. It's a bit off-topic, but does anybody know how to perform this in Acces SQL?
This will be my last question in this thread, thank you.
 
best to post your last question in the access forum

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top