Reputation: 283
What I want to do is create a stored procedure that will insert into one table from another table, but the amount of rows being inserted will vary depending on the amount of instances of c_id in the 'basket' table.
CREATE PROCEDURE `proc_Transaction` ()
BEGIN
INSERT INTO transactions
(t_id, p_id, u_id, price, qty, total) status, when_sold)
VALUES
(@t_id, @p_id, @c_id, @Price, @Qty, @total, );
SELECT p_id, c_id, qty FROM basket;
END
I want to insert into the above 'transactions' table from my 'basket' table for every instance of c_id equalling a specified value. So there could be just one or many rows being inserted. t_id will stay constant for each row inserted.
Upvotes: 0
Views: 217
Reputation: 1269673
Is this what you want?
INSERT INTO transactions (t_id, p_id, u_id, price, qty, total)
SELECT @t_id, p_id, c_id, qty, @total FROM basket;
Upvotes: 3