[thelist] returning the row id after an insert (MS SQL 7)

rudy r937 at interlog.com
Thu Dec 6 11:10:57 CST 2001


>What I'm doing now is inserting new rows into my table and then selecting
>the row id with a separate sql statement based on the data inserted in the
>prior sql statement.  Isn't there a way to do this in one statement rather
>than 2?  Any help is much appreciated.

hi chris

at least you are doing the second query based on the *data* of the insert,
rather than using "select max(pkey)"

  see http://lists.evolt.org/archive/Week-of-Mon-20010806/010771.html

querying back using data is actually a pretty decent way of doing it,
because it's compatible with multithreading, and does not require you to
set the two statements into a transaction block

see also http://lists.evolt.org/archive/Week-of-Mon-20010910/013174.html

anyhow, since you are using sql/server, you should look into @@identity

rudy





More information about the thelist mailing list