Results 1 to 5 of 5

Thread: exec stored proc -- return record id?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Austin
    Posts
    397

    exec stored proc -- return record id?

    how do you return a record number once you insert data into a sql table?

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: exec stored proc -- return record id?

    SELECT @@IDENTITY will get you the id value inserted. You could return it in an OUTPUT parameter.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Austin
    Posts
    397

    Re: exec stored proc -- return record id?

    what is an OUTPUT parameter?

    this is what i came up with....?

    Code:
    create  procedure [p_save_new]  @sheetname varchar(1000), @sheetdata text, @categoryid int, @username nvarchar(50) as
    insert into tblcheatsheet
    (sheetname, sheetdata,categoryid,active)
    values (@sheetname, @sheetdata, @categoryid  , '1')
    
    insert into tblWhoWhen
    values(@@IDENTITY , @username, Getdate())
    Last edited by texas; May 24th, 2005 at 09:59 AM.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: exec stored proc -- return record id?

    create procedure [p_save_new] @sheetname varchar(1000), @sheetdata text, @categoryid int, @username nvarchar(50), @ReturnValue INT OUTPUT as

    insert into tblcheatsheet
    (sheetname, sheetdata,categoryid,active)
    values (@sheetname, @sheetdata, @categoryid , '1')

    SELECT @ReturnValue = @@IDENTITY FROM tblcheatsheet

    insert into tblWhoWhen
    values(@ReturnValue , @username, Getdate())

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Austin
    Posts
    397

    Re: exec stored proc -- return record id?

    what was wrong with the way i was doing it?

Posting Permissions

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



Click Here to Expand Forum to Full Width