zwwcn

Just another WordPress.com site

MYSQL procedure

DELIMITER //
CREATE PROCEDURE deletePrepaymentWithoutPaymentItems(IN p_invoice_id INT(20))
BEGIN
DELETE FROM OP_LEAD_STATUS_XREF WHERE INVOICE_ID =p_invoice_id;

DROP table if exists TMP_INV_CONTACT;

CREATE TABLE TMP_INV_CONTACT as SELECT * FROM OP_INVCONTACTTYPE WHERE INVOICE_ID=p_invoice_id;

DELETE FROM OP_INVCONTACTTYPE WHERE INVOICE_ID=p_invoice_id;

DELETE FROM OP_INVCONTACT WHERE OBJECT_ID IN (SELECT INVCONTACT_ID FROM  TMP_INV_CONTACT);

DROP table if exists TMP_INV_ADDRESS;

CREATE TABLE TMP_INV_ADDRESS as SELECT * FROM OP_INVADDRESSTYPE WHERE INVOICE_ID=p_invoice_id;

DELETE FROM OP_INVADDRESSTYPE WHERE INVOICE_ID=p_invoice_id;

DELETE FROM OP_INVADDRESS WHERE OBJECT_ID IN (SELECT INVADDRESS_ID FROM TMP_INV_ADDRESS);

DELETE FROM OP_INVOICE WHERE OBJECT_ID =p_invoice_id;

END //
DELIMITER ;

——————————–

call deletePrepaymentWithoutPaymentItems(3984571);

———————————

DROP PROCEDURE IF EXISTS `deletePrepaymentWithoutPaymentItems`;

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: