MrAntunes
10/7/2015 - 10:23 AM

Copy line to insert in the same table, using temporary tables

Copy line to insert in the same table, using temporary tables

	-- copia a linha do produto original para criar a sample
	CREATE TEMPORARY TABLE tmptable_1 SELECT * FROM product WHERE idproduct = p_idproduct;
	UPDATE tmptable_1 SET idproduct = NULL, url = NULL;
	INSERT INTO product SELECT * FROM tmptable_1 LIMIT 1;
	DROP TEMPORARY TABLE IF EXISTS tmptable_1;

	SELECT LAST_INSERT_ID() into @idproduct;
	
	-- copia os shipments do produto original para criar a sample
	CREATE TEMPORARY TABLE tmptable_1 SELECT * FROM product_shipping WHERE idproduct = p_idproduct;
	UPDATE tmptable_1 SET idshipping = NULL, idproduct = @idproduct, ativo = 1;
	INSERT INTO product_shipping SELECT * FROM tmptable_1;
	DROP TEMPORARY TABLE IF EXISTS tmptable_1;