Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

a record is just inserted

Posted on 2011-03-13
4
Medium Priority
?
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 9

Assisted Solution

by:sshah254
sshah254 earned 124 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 128 total points
ID: 35125577
insert tableXXX ...

SELECT IDENT_CURRENT ('tableXXX')
0
 
LVL 11

Assisted Solution

by:JoeNuvo
JoeNuvo earned 124 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 124 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

596 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