|
|
Question : creating a stored procedure to update multiple tables
|
|
Hi,
I need to create a stored procedure that updates the same field in 2 tables when the user submits a form from an ASP page.
When the user selects a new location from a list (on the ASP page) I need the stored procedure to update one table (possibly multiple rows within that table), then update another table (again, possibly mutliple rows).
Ideally, I'd also like some validation in there as well if possible. The tables that will need updating will depend on what time of item the user has selected to change the location for. For instance, if the item the user has selected is a book then the stored procedure will need to change the field 'ItemLocation' in T_Books and T_Books2, but if the item is a DVD then the stored procedure will need to update 'ItemLocation' in T_DVDs and T_DVDs2. The stored procedure should be able to look in T_Items to find out what type of item the user has elected to change the location for (the field name is 'ItemType').
Hope all that makes sense - i'm not sure if it's simple or not, but I don't have a massive amount of experience with stored procedures and I don't want to mess it up.
Can anyone help?
Thanks SWD
|
Answer : creating a stored procedure to update multiple tables
|
|
Hi SurreyWebDesigner,
Something like:
Create Procedure UpdateLocations(@Item varchar(50),@Location varchar(50)) As
If (Select ItemType From T_Items Where ItemName=@Item) = 'Book' Begin Update T_Books Set ItemLocation = @Location Where ItemName = @Item Update T_Books2 Set ItemLocation = @Location Where ItemName = @Item End Else Begin Update T_DVDs Set ItemLocation = @Location Where ItemName = @Item Update T_DVDs2 Set ItemLocation = @Location Where ItemName = @Item End
Tim Cottee
|
|
|
|
|