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 |
|
robson
Starting Member
22 Posts |
Posted - 2008-04-29 : 04:22:55
|
| I believe we can you multiple statements in stored procedures?Suppose I have a stored procedure and I pass parameters to this SP.What I am aiming for is to pass some values to the stored procedure, use a select statement to retrieve some values, then have two update statements as below. Updating the same table but with opposite values, both passed as a parameter and retrived, as given below:CREATE sp_temp_proc @order_id int, @order_position int, @temp_order_id OUTPUT @temp_order_position OUTPUT,SELECT order_id AS temp_order_id FROM <TABLE> WHERE order_position < @order_position@temp_order_id = temp_order_idUPDATE <TABLE> SET order_position = @order_position WHERE order_id = @temp_order_idUPDATE <TABLE> SET order_position = @temp_order_position WHERE order_id = @order_id |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-04-29 : 05:01:35
|
| Yup. You can do this. Only think is you might need a table variable or temporary table to store id values from select clause as it will be returning a resultset. |
 |
|
|
robson
Starting Member
22 Posts |
Posted - 2008-04-29 : 05:57:30
|
| I was able to create multiple statements within the stored procedure with some trial and error as discussed above. |
 |
|
|
|
|
|