Solved

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

Posted on 2011-02-15
2
906 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
2 Comments
 
LVL 32

Accepted Solution

by:
ewangoya earned 500 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now