How to get an id from an insert into an update?

Results 1 to 3 of 3

Thread: How to get an id from an insert into an update?

  1. #1
    Join Date
    Dec 1969
    Posts
    321

    Default How to get an id from an insert into an update?

    Hi there<BR><BR>I&#039;ve got a stored procedure that does an insert to a table. In the same stored procedure I want to grab the id after the insert and give it to the update. Any ideas examples.<BR><BR>thanksa.

  2. #2
    Join Date
    Dec 1969
    Posts
    972

    Default RE: How to get an id from an insert into an update

    Since you are talking about stored procedures I assume you are working with SQL Server.<BR><BR>Look up the @@IDENTITY in books-online:<BR><BR>CREATE PROCEDURE dbo.MyProcedure<BR> @MyValue int<BR>AS<BR>DECLARE @ID int<BR>INSERT INTO MyTable (MyColumn) VALUES (@MyValue)<BR>SET @ID = @@IDENTITY<BR><BR>RETURN @ID<BR>GO

  3. #3
    Join Date
    Dec 1969
    Location
    Los Angeles, CA
    Posts
    21,192

    Default OR

    RTFFAQs to get an idea as to how it is done<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •