Solved

a record is just inserted

Posted on 2011-03-13
4
244 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:VBdotnet2005
4 Comments
 
LVL 9

Assisted Solution

by:sshah254
sshah254 earned 31 total points
ID: 35125271
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
 
LVL 5

Accepted Solution

by:
Kelmen earned 32 total points
ID: 35125577
insert tableXXX ...

SELECT IDENT_CURRENT ('tableXXX')
0
 
LVL 11

Assisted Solution

by:JoeNuvo
JoeNuvo earned 31 total points
ID: 35125691
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
 
LVL 11

Assisted Solution

by:yuching
yuching earned 31 total points
ID: 35125710
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

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question