Getting IDENTITY value of a row that was just INSERTED

Getting IDENTITY value of a row that was just INSERTED

Post by Russ Youn » Fri, 30 Oct 1998 04:00:00



How do I determine the IDENTITY value of a row that I just INSERTED into a
table?  I want to put the identity of the row that was just inserted into a
row in a different table that I'll be inserting.

Note:  the first table being inserted into has an auto-incrementing identity
property defined.

Thanks,

Russ Young
Bellevue WA

 
 
 

Getting IDENTITY value of a row that was just INSERTED

Post by a » Fri, 30 Oct 1998 04:00:00


/* This is how I did it It probably is not the best way */

Create Trigger TrigTI
On T1
For Insert


As


                From inserted

        INSERT INTO T2(MYIDT2)



Quote:> How do I determine the IDENTITY value of a row that I just INSERTED into
a
> table?  I want to put the identity of the row that was just inserted into
a
> row in a different table that I'll be inserting.

> Note:  the first table being inserted into has an auto-incrementing
identity
> property defined.

> Thanks,

> Russ Young
> Bellevue WA


 
 
 

Getting IDENTITY value of a row that was just INSERTED

Post by Rogers, Lawrenc » Fri, 30 Oct 1998 04:00:00



the just inserted row.
> -----Original Message-----

> Posted At: Thursday, October 29, 1998 3:35 PM
> Posted To: programming
> Conversation:      Getting IDENTITY value of a row that was just INSERTED
> Subject:   Re: Getting IDENTITY value of a row that was just
> INSERTED

> /* This is how I did it It probably is not the best way */

> Create Trigger TrigTI
> On T1
> For Insert


> As


>            From inserted

>    INSERT INTO T2(MYIDT2)



> > How do I determine the IDENTITY value of a row that I just INSERTED
> into
> a
> > table?  I want to put the identity of the row that was just inserted
> into
> a
> > row in a different table that I'll be inserting.

> > Note:  the first table being inserted into has an auto-incrementing
> identity
> > property defined.

> > Thanks,

> > Russ Young
> > Bellevue WA

 
 
 

1. Getting IDENTITY value of newly inserted row

Hi,

I have a quick question.  How can I get the identity value of a newly
inserted row using the Recordset object.  Here is what I am trying right
now:

        Set toRS = New Recordset
        toRS.Open "PMSUsers", oDb.CN, adOpenForwardOnly, adLockOptimistic
        toRS.AddNew
        toRS("UsrLoginID") = strEncUsername
        toRS("UsrPassword") = strEncPassword
        toRS("CustomerID") = CustomerID
        toRS.Update
        AddUser = toRS("UsrID") 'Return New UserID to calling function

The UsrID column is defined as an IDENTITY column in SQL.  However, it's
always returning 0 for some reason, and according to SQL Server, new ids are
being correctly generated.  Any help would be appreciated.  Thanks.

Xin Li

2. DATA SAMPLED ON TIME

3. Getting the identity value of a newly inserted row

4. Summer and Winter time

5. Getting the identity of the row just inserted

6. SQL6.5: how to add NOT NULL columns in T-SQL

7. Recordset-Getting the ID of a row inserted when the ID is IDENTITY/AUTOINCREMENT

8. Getting the new identity value from an Insert query

9. Getting back an identity field value after an insert SQL statement

10. getting identity value after insert

11. Getting auto-incremented identity value on insert...

12. Getting Back Identity column value on Insert using RDS