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 |
|
Sirrombor
Starting Member
12 Posts |
Posted - 2003-08-04 : 14:01:50
|
| Hi,I have a stored proc that is called from a web script. I need to pass some parameters into it for inserting, return the Identity and then pass the identity value and some other params to another stored proc for inserting.Can someone give me an example or link to where I can learn how to accomplish this?Here is an example of what I am trying...ALTER PROCEDURE dbo.sp_NewPosting@PostSubject nvarchar (256),@CustNumber varchar (1000),@UserID int,@CustQuestion ntext,ASINSERT INTO dbo.Tbl_Postings(PostSubject, CustNumber,UserID,CustPostDate)VALUES(@PostSubject,@CustNumber,@UserIDGETDATE())SET @PostID = @@IDENTITY/* Above works can't figure out how to then fire off another SP and pass it values...*/EXEC sp_NewQuestion @PostID, @CustQuestion, @UserID/* I need to get the value of @PostID and pass it to the other proc along with the rest of the Web Page form values.*//* I would have done an additional insert but I want a separate stand alone proc that I can call alone for another piece of the site.*/ |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-08-04 : 14:14:24
|
| What is the error that you are getting?It worked fine for me when I ran your code (modified to fit my sample tables and stored procedures).CREATE PROCEDURE dbo.sp_NewPosting(@PostSubject nvarchar (256), @CustNumber varchar (1000), @UserID int, @CustQuestion ntext)ASINSERT INTO dbo.Tbl_Postings(PostSubject, CustNumber,UserID,CustPostDate)VALUES(@PostSubject,@CustNumber,@UserIDGETDATE())SET @PostID = @@IDENTITYEXEC sp_NewQuestion @PostID, @CustQuestion, @UserIDRETURNTara |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-08-04 : 14:15:39
|
| Here is the code that I wrote to test it:----Sample Tablescreate table table1(Column1 int identity (1, 1) not null,Column2 int not null)create table table2(ColumnA int not null,ColumnB int)----Stored procedurescreate proc usp_test2(@holdidentity int, @value2 INT)asinsert into table2 (ColumnA, ColumnB) values (@holdidentity, @value2)returncreate proc usp_Test1(@value1 INT, @value2 INT)asdeclare @holdidentity intinsert into table1 (Column2) values(@value1)set @holdidentity = @@IDENTITYEXEC usp_test2 @holdidentity, @value2return----Now run first stored proc that calls secondexec usp_test1 1, 2----Now check the dataselect * from table1select * from table2----Now drop the objectsdrop proc usp_test1drop proc usp_test2drop table table1drop table table2Tara |
 |
|
|
Sirrombor
Starting Member
12 Posts |
Posted - 2003-08-04 : 15:12:08
|
| I got it working!I had PostID declared wrong in the 2nd table....Thanks Tara |
 |
|
|
|
|
|
|
|