Anyway, below is a very simple procedure that first SELECTS records existing in the user table (tbluser) matching the value of the username passed in as a parameter to the stored procedure.
Only if the row count of the recordset is equal to one does it insert the values into the second table
The logic of this procedural flow is deeply 'flawed' of course but you can work it out for yourself as I suspect you are merely learning 'how' to grab a value from one table and throw it into another
Code:
CREATE PROCEDURE dbo.usp_insertUserInfo @username varchar(100) AS DECLARE @mycount int SELECT @mycount= (userid) FROM tblusers WHERE username=@username IF @@rowcount=1 INSERT tbluserinfo (userid,firstname) SELECT userid,username FROM tblusers WHERE username=@username GO
Leave a comment: