Troy,
     The problem is that you could have two people calling this at
approximately the same time and then you might (?) not get the correct row
for one of them. What about using a sequence and grabbing the nextval from
it at the beginning of the process, this way you have a unique value and can
do inserts/updates at your leisure (making the field not auto increment).


Andy

-----Original Message-----
From: Troy Sniff [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 21, 2002 11:10
To: [EMAIL PROTECTED]
Subject: RE: Returning auto incremented value on insert


Maybe one of these days I can do a bit more research to find out why. If
I ever do, I'll post my findings.

Luckily this insert will only be one row at a time.

I ended up inserting and then reading what I just inserted to grab the
value.

Troy


> -----Original Message-----
> From: John Boucher [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, March 21, 2002 3:42 PM
> To: 'Troy Sniff'; [EMAIL PROTECTED]
> Subject: RE: Returning auto incremented value on insert
>
>
> Just a comment:
> It seems to me that the reason you can't have the ID of the
> last inserted
> row automatically returned in a variable is that some (most?)
> databases
> allow INSERT to insert more than one row at a time.
> This would affect auto-increment as well.
>
> Sure, you may only be inserting one row _now_, but what about
> the times when
> someone inserts many?
>
>
> -----Original Message-----
> From: Troy Sniff [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, March 21, 2002 2:26 PM
> To: [EMAIL PROTECTED]
> Subject: RE: Returning auto incremented value on insert
>
>
> Yeah I figured I would have to go back in.
>
> I have a timestamp being placed in. I can do a select using it and
> another value to get the record number after the insert.
>
> I sure wished Access support @@IDENTITY or something like it.
>
> Troy
>
> > -----Original Message-----
> > From: MacGown, Peter [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, March 21, 2002 2:51 PM
> > To: 'Troy Sniff'; [EMAIL PROTECTED]
> > Subject: RE: Returning auto incremented value on insert
> >
> >
> > I work with MS Access quite a bit and you can't quite do what
> > you want in
> > Access either.  What I do there is create a unique
> > combination of something
> > like the following:
> >
> > TIMESTAMP as datefield
> > USERNAME as text(50)
> >
> > SAVETIME = NOW()
> >
> > I write the record and then, do a select on the record where
> > TIMESTAMP =
> > SAVETIME AND USERNAME = CURRENT USER NAME
> >
> > I suppose you could even use a session number as well if you
> > could get it.
> >
> > I have been programming pretty intensely with MS Access for a
> > number of
> > years now and this is the only way I found to do what you
> > want.  I'm not
> > quite sure how to do it in Perl since I am a newbie at it,
> > but I'm sure you
> > could use the same approach.
> >
> > I'm very interested in how you get Perl to work with MS
> > Access databases.  I
> > can get it to work using the command line, but I can't get it
> > to work using
> > CGI.
> >
> > I hope that this was helpful.
> >
> > Thanks,
> > Pete MacGown
> > AT&T Broadband
> >
> > -----Original Message-----
> > From: Troy Sniff [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, March 21, 2002 4:09 PM
> > To: [EMAIL PROTECTED]
> > Subject: Returning auto incremented value on insert
> >
> >
> > I am performing an insert into an access table where the
> > primary key is
> > set to auto increment.
> >
> > When I insert a record, is there an easy way to grab the
> value created
> > by the auto increment without having to go back in read the newly
> > created record?
> >
> > I need the value to display a result such as:
> >
> > "Your information has been added.  The record number assigned
> > was 1000.
> > We recommend you write this down for future reference".
> >
> > Troy
> >
> >
> >
>
>


________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


__________________________
This email and any files transmitted with it are confidential and intended solely for 
the use of the individual or entity to whom they are addressed. The contents are 
confidential and may be privileged.
Any views or opinions expressed are those of the sender and may not reflect the views 
or opinions of the company and the company accepts no liability in respect thereof.
If you have received this email in error please notify [EMAIL PROTECTED] 
immediately.

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Reply via email to