Solved

a record is just inserted

Posted on 2011-03-13
4
245 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 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

738 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