Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2004
    Posts
    660

    Unanswered: Get ID from store procedure

    I would like to create a employee store procedure to insert a record and mean while i can retrieve the EmployeeID for the record just inserted. Can you show me how to create a store procedure like this. Now i have a insert store procedure in the following:

    CREATE PROCEDURE AddEmployee
    (@efname nvarchar(20),
    @elname nvarchar(20)
    )
    AS

    insert into tblEmployeeName
    (EmployeeFName, EmployeeLName)
    values (@efname,@elname)
    GO



    Thanks.

  2. #2
    Join Date
    Jun 2003
    Posts
    269
    Quote Originally Posted by yyu
    I would like to create a employee store procedure to insert a record and mean while i can retrieve the EmployeeID for the record just inserted. Can you show me how to create a store procedure like this. Now i have a insert store procedure in the following:

    CREATE PROCEDURE AddEmployee
    (@efname nvarchar(20),
    @elname nvarchar(20)
    )
    AS

    insert into tblEmployeeName
    (EmployeeFName, EmployeeLName)
    values (@efname,@elname)
    GO



    Thanks.
    Are u using identity column for Employee ID? then u can retrieve that value by,

    SELECT @@IDENTITY
    I love cursor,though I never use it.Cos' I dont want to misuse it.
    ----------------------------------------------

    ----cheers
    ----http://mallier.blogspot.com

  3. #3
    Join Date
    Mar 2003
    Location
    Reading, UK
    Posts
    70
    is ur EmployeeId an identity column ??

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Actually, you want to use SCOPE_IDENTITY instead...
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  5. #5
    Join Date
    Mar 2004
    Posts
    660
    Yes, the EmployeeID is identity. So where to add to my store procedure.
    Also can you give me a reference link for how to create a store procedure.
    Many thanks.

  6. #6
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Why certainly

    http://www.sqlteam.com/store.asp


    As for sprocs..you could use a template

    http://weblogs.sqlteam.com/brettk/ar...5/25/1378.aspx

    Probably will handle 99% of your sproc requirements
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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