Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Return parameters in Strored procedures

Return parameters in Strored procedures

Scheduled Pinned Locked Moved Database
databasecsharpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abbas_Riazi
    wrote on last edited by
    #1

    I'm writing a new database driven application. In one of my stored procedures, I want to add user data and get back user id from table. The table has this structure:

    ID, numeric, identity with identity seed =1,
    username, char(25)
    email, char(40)

    my stored procedure looks like this:

    ALTER PROCEDURE dbo.InsertNewUser
    (
    @UserName char(25),
    @email char(40),
    @ID numeric OUTPUT
    )
    AS
    INSERT INTO Users
    (UserName, email)
    VALUES (@UserName, @email);
    RETURN

    How I changed the stored procedure to return the new added user's ID? I code in C#. Best regards, A. Riazi

    M 1 Reply Last reply
    0
    • A Abbas_Riazi

      I'm writing a new database driven application. In one of my stored procedures, I want to add user data and get back user id from table. The table has this structure:

      ID, numeric, identity with identity seed =1,
      username, char(25)
      email, char(40)

      my stored procedure looks like this:

      ALTER PROCEDURE dbo.InsertNewUser
      (
      @UserName char(25),
      @email char(40),
      @ID numeric OUTPUT
      )
      AS
      INSERT INTO Users
      (UserName, email)
      VALUES (@UserName, @email);
      RETURN

      How I changed the stored procedure to return the new added user's ID? I code in C#. Best regards, A. Riazi

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      If this is SQL Server 2000:

      SET @ID = SCOPE_IDENTITY()

      If SQL Server 7.0, you have to use the @@IDENTITY variable; however, this may produce incorrect results if a trigger fires which inserts rows. Stability. What an interesting concept. -- Chris Maunder

      C 1 Reply Last reply
      0
      • M Mike Dimmick

        If this is SQL Server 2000:

        SET @ID = SCOPE_IDENTITY()

        If SQL Server 7.0, you have to use the @@IDENTITY variable; however, this may produce incorrect results if a trigger fires which inserts rows. Stability. What an interesting concept. -- Chris Maunder

        C Offline
        C Offline
        cnet2008
        wrote on last edited by
        #3

        SQL SERVER2000 SET @ID = @@IDENTITY you are welcome to visit my Blog

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups