?
Solved

a record is just inserted

Posted on 2011-03-13
4
Medium Priority
?
248 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
I have a large data set and a SSIS package. How can I load this file in multi threading?
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.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Suggested Courses

770 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