Click here to Skip to main content
16,021,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to use two update statements in mysql as stored procedure
it only shows the number of affected rows for last update query
i need it combined

SQL
DELIMITER //
 CREATE PROCEDURE SP_Lock_update(IN locked int(1),IN user_id int)
    BEGIN
        update user_register , comments,articles
set
user_register.locked=locked,
comments.locked=locked,
articles.locked=locked
where
user_register.user_id=user_id
and
comments.user_id=user_id
and
articles.user_id=user_id;

update comments
set
locked=locked
where article_id in (select article_id from articles where user_id=user_id);
    END //
 DELIMITER ;
Posted

1 solution

What you want to do is use the @@ROWCOUNT variable after each statement and put that number into a variable. Then output that variable from your stored procedure. This Stack Overflow question will help out a bit:

http://stackoverflow.com/questions/1103260/return-number-of-rows-affected-by-update-statements[^]

Edit
Sorry, I misread the question as being SQL. For MySQL, the concept is the same, but you use the ROW_COUNT() construct instead of @@ROWCOUNT (at least for modification statements like you are doing). If you wanted to capture rows from a SELECT, use the FOUND_ROWS() construct.
 
Share this answer
 
v2
Comments
mohanrajkiller 18-Dec-12 7:23am    
i have asked for mysql your answer was for mssql
Tim Corey 27-Dec-12 9:59am    
Sorry about that. I've updated my answer. It is basically the same thing, only you need to use a different construct name.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900