dodgerfan
asked on
SQL Server 2008 Stored Procedure - updating multiple tables
I have a stored procedure that updates the data in a table based on input values. Once that part is done, I want the procedure to take one of the input parameters and return a record from a view, a different recordset. Using the data returned from the view, I want to update another table. Is there a way to do this?
ASKER
Yes, sorry about the vagueness. I should have been more detailed. My current sp looks lke this:
create procedure [dbo].[returnBook]
@rentid int,
@memberId int,
@returneddate datetime,
@bookid Int
AS
UPDATE bookrental
SET
returneddate=@returneddate
WHERE rentId=@rentalId And memberId = @memberId
This works. Now I need to open another query to find the next book for that member, call vwNextBook with the memberid being the value. Then I need to take that data and insert into the bookrental table, with some of the data already captured in the original variables, too. So take the bookId returned in this query and insert it with memberid and a new date into the oriiginal bookrental table. I think this makes sense. I will try what you have already posted, too.
create procedure [dbo].[returnBook]
@rentid int,
@memberId int,
@returneddate datetime,
@bookid Int
AS
UPDATE bookrental
SET
returneddate=@returneddate
WHERE rentId=@rentalId And memberId = @memberId
This works. Now I need to open another query to find the next book for that member, call vwNextBook with the memberid being the value. Then I need to take that data and insert into the bookrental table, with some of the data already captured in the original variables, too. So take the bookId returned in this query and insert it with memberid and a new date into the oriiginal bookrental table. I think this makes sense. I will try what you have already posted, too.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help. I got it working right with your help.
Steps 2 and 3 can be done in one query, instead of retrieving and storing it temporarily.
Open in new window