Click here to Skip to main content
15,886,798 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to write a Stored Procedure which do 2 tasks
1: Get ID of the record on base on username
2: update the record on base of the id we got in step 1

My table structure is like this
ID Name Username Password Gender

ID is primary key and autoincrement

I've write my sp as this

ALTER PROCEDURE [dbo].[insert_FBSignUp]
	-- Add the parameters for the stored procedure here
	@name nvarchar(200),
        @uname nvarchar(200),
        @pwd nvarchar(50),
        @gender nvarchar(10)
AS
BEGIN
	Select id from dbo.tblUsers where Username=@Email	
END


I'm confusing about what should i do next i mean where and how i write my update statement
Posted

You are missing @Email parameter in the list. Declare a variable to hold the value of Id.
SQL
ALTER PROCEDURE [dbo].[insert_FBSignUp]
	-- Add the parameters for the stored procedure here
	@name nvarchar(200),
        @uname nvarchar(200),
        @pwd nvarchar(50),
        @gender nvarchar(10),
        @Email nvarchar(200) --missing parameter
AS
BEGIN
 
DECLARE @ID int
  Select  @ID = id from dbo.tblUsers where Username=@Email

     UPDATE dbo.tblUsers
      SET (uname = @uname,
           pwd = @pwd,
           gender = @gender)
      WHERE id = @ID
 
Share this answer
 
SQL
ALTER PROCEDURE [dbo].[insert_FBSignUp]
	-- Add the parameters for the stored procedure here
	@name nvarchar(200),
        @uname nvarchar(200),
        @pwd nvarchar(50),
        @gender nvarchar(10)
AS
BEGIN

        DECLARE @ID int
	SET @ID = (Select id from dbo.tblUsers where Username=@Email)

        UPDATE dbo.tblUsers
        SET (name = @name,
             uname = @uname,
             pwd = @pwd,
             gender = @gender)        
        WHERE id = @ID

END
 
Share this answer
 
v3
Comments
RaisKazi 25-Nov-11 1:31am    
Edited: Added "pre" tag.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900