?
Solved

sql  stored procedure + Return the id of the last inserted record

Posted on 2011-02-15
2
Medium Priority
?
916 Views
Last Modified: 2012-05-11
I have this code In my stored procedure.  I want to get the value of the id for the record that was just inserted so that i can use it to insert into another table. How would i do so?

 IF @ImageName      <> ''
      begin
  INSERT INTO Images(Image_Data, Image_Name, Content_Type)
      VALUES (@ImageData, @ImageName, @ImageContentType)
      
end
 

0
Comment
Question by:vbnetcoder
[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
2 Comments
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 2000 total points
ID: 34902498

try this

declare @LastID int

IF @ImageName      <> ''
begin
  INSERT INTO Images(Image_Data, Image_Name, Content_Type)
  VALUES (@ImageData, @ImageName, @ImageContentType)

  set @LastID = @@Identity
END
0
 

Author Closing Comment

by:vbnetcoder
ID: 34902568
ty
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

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