Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
peterwilson
Starting Member
15 Posts |
Posted - 2008-07-15 : 06:34:31
|
hi friends,i m having 1 proble so plz help me ...c actually i want to insert the record into multiple table and that i m doing with the help of Store Procedure.i m inserting a value from ASP form liketable-Studand SP - sp_StudAdd cmd.Parameters.Append cmd.CreateParameter("@User_name", adVarChar, adParamInput,50,request.form("1un")) cmd.Parameters.Append cmd.CreateParameter("@Password", adVarChar, adParamInput,50,request.form("2pas")) cmd.Parameters.Append cmd.CreateParameter("@First_name", adVarChar, adParamInput,50,request.form("3fn")) cmd.Parameters.Append cmd.CreateParameter("@Last_name", adVarChar, adParamInput,50,request.form("4ln")) cmd.Parameters.Append cmd.CreateParameter("@Add_1", adVarChar, adParamInput,50,request.form("5add")) cmd.Parameters.Append cmd.CreateParameter("@Add_2", adVarChar, adParamInput,50,request.form("6add"))and simultaniously i m aslo inserting this value into another table table -Student_recordCREATE PROCEDURE sp_StudAdd@User_name varchar(50),@Password varchar(50),@First_name varchar(50),@Last_name varchar(50)ASset NoCOunt onINSERT INTO Stud(User_name,Password,First_name,Last_name)VALUES(@User_name, @Password, @First_name, @Last_name)Exec sp_Stud_Per_Record @User_name,@PasswordGOi m declareing ID field as Autoincerement i have to copy my ID field into my another talbe which is "Stud_Add"remaing 4 values get added but ID not plz chk ..wht mistake i was done --this is my sp_Stud_Per_RecordCREATE PROCEDURE sp_Stud_Per_Record@ID varchar(50),@User_name varchar(50),@Password varchar(50),@Branch varchar(50),@Addedon varchar(50)AS--SET NOCOUNT ON set @ID = ( select top 1 ID from Stud where User_name='@User_name' and Password='@Password' )print @IDINSERT INTO Stud_Per_Record(ID,Name,Pwd)VALUES(@ID,@User_name, @Password)GO |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-15 : 06:53:25
|
INSERT INTO Stud_Per_Record(ID,Name,Pwd)VALUES(scope_identity(),@User_name, @Password)MadhivananFailing to plan is Planning to fail |
 |
|
peterwilson
Starting Member
15 Posts |
Posted - 2008-07-15 : 07:00:34
|
thkxis it ok , or can i make FK relation with this 2 |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-15 : 07:15:58
|
quote: Originally posted by peterwilson thkxis it ok , or can i make FK relation with this 2
YesMadhivananFailing to plan is Planning to fail |
 |
|
peterwilson
Starting Member
15 Posts |
Posted - 2008-07-15 : 07:26:16
|
plz INSERT INTO Stud_Per_Record(ID,Name,Pwd)VALUES(scope_identity(),@User_name, @Password)explain me this , i dont know much abot scopr_identity()actually whr i can put this , in my code so i can get the ID(rollno) of first table to another table.hope u gt wt i want to say |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-15 : 08:54:47
|
quote: Originally posted by peterwilson plz INSERT INTO Stud_Per_Record(ID,Name,Pwd)VALUES(scope_identity(),@User_name, @Password)explain me this , i dont know much abot scopr_identity()actually whr i can put this , in my code so i can get the ID(rollno) of first table to another table.hope u gt wt i want to say
Read about scope_identity() in sql server help fileMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|