Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I'm trying to create a stored procedure with a mysql Database that queries on one database table and uses the results to update another database table.

I'm not sure how to go about this. Any advice/solutions would be much appreciated!

Here's a piece of sample code to give you an idea of what I'm attempting to do.

SAMPLE CODE:
SQL
DELIMITER //
CREATE PROCEDURE()
BEGIN
SELECT @count := COUNT(col) FROM DB1.TBL1;
UNION
UPDATE DB2.TBL2 SET @count = col;
END//
Posted
Updated 16-Nov-10 18:50pm
v2

1 solution

Well for starters in the UPDATE statement the the SET section is backwards it should be SET col = @count and you haven't declared the @count variable, not sure if this last part matters in MySql though.

However something else to try is this[^].
Or see if this, which is just from the link, works.
SQL
UPDATE DB2.TBL2 a, DB1.TBL1 b
SET a.col= COUNT(b.col)
 
Share this answer
 

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