[thelist] Key ID of Record Just Created?

Mark Rees mrees at itsagoodprice.com
Tue Aug 23 11:22:34 CDT 2005

Please send replies to the list (hit reply-all instead of reply). My reply

> > > In ASP.NET / VB.NET, is it possible to discover the key_id of a record
> just
> > > created?  Key ID column is doc_id.
> > If key_id is an SQL Server identity column, then
> > after the insert will return this value. It is my understanding that
> if
> > another process inserts another record in between times, this will
> > the value you want, ie the key_id of the record just inserted by your
> script
> That is exactly what I'm after.  The column name is doc_id, and it is
> designated in MS SQL as the key id for the table.  I'm not sure what you
> mean by "If key_id is an SQL Server identity column".

Try looking here

Have you got SQL server Enterprise Manager installed on your PC? If so, you
should have Books Online as well. It is an invaluable resouce for answering
questions such as this.

Also, When I use
> SELECT @@IDENTITY, how do I then re-use this later?  For example, later I
> want to run a query against this record, how do I refer to the value?  Can
> add it to a variable, such as
> DIM valDocID as Integer = SELECT @@IDENTITY

I don't know anything about .NET syntax, but basically yes, you will have to
run that SELECT query, and assign the results to a variable

> ??
> TIA!!!

More information about the thelist mailing list