I'm just starting to write stored procedures. It took me hours to get this simple thing to work. Now I'm wondering what is the right way to do this. All I want to do is add a new row to the Users table and return the newly created UserID.
Thanks for any advice,
Jim
Code:
USE MessyTextSQL GO /****** Object: StoredProcedure [dbo].[AddNewUser] Script Date: 11/06/2011 07:40:19 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].AddNewUser -- ============================================= -- Author: Jim Wolf -- Create date: 11/7/11 -- Description: Add new MessyText project -- ============================================= -- Add the parameters for the stored procedure here @NewUserID int output AS BEGIN SET NOCOUNT ON; -- Insert statements for procedure here INSERT INTO Users(UserID) VALUES (99999999) SET @NewUserID =SCOPE_IDENTITY() Update Users Set UserID = cnt from Users where Users.cnt =@NewUserID END
Jim
Comment