a record is just inserted

How can I get idRequest when a record is just inserted?  I need it to update another table.
Insert into mytable (idrequest, etc...)

idReqest    orderdate  address
1                3/10/2011  123 test
2                3/11/2011  456 test
VBdotnet2005Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
KelmenConnect With a Mentor Commented:
insert tableXXX ...

SELECT IDENT_CURRENT ('tableXXX')
0
 
sshah254Connect With a Mentor Commented:
If this is a single thread process, then just get

select max(id) as id1 from table, and use the value of id1 to store in another table.

If it is a multi-threaded process (something like a webserver), then you'll need to store something specific, like a session variable

insert into mytable (session, orderdate, address, etc.)

now select max(id) as id2, session from table where session = session_variable group by session

Ss
0
 
JoeNuvoConnect With a Mentor Commented:
if you just insert 1 record into table and if idRequest is IDENTITY

after INSERT INTO statement, you can get the value of it using SELECT @idRequest = SCOPE_IDENTITY()
(@idRequest must declare earlier, and SELECT command must run right after INSERT statement)

then you can do other thing with @idRequest after.
0
 
yuchingConnect With a Mentor Commented:
You can refer to below link for the ways of getting current identify value
http://sqlservercodebook.blogspot.com/2008/03/to-get-current-identity-value-from.html
0
All Courses

From novice to tech pro — start learning today.