Rows not deleting from table
Posted by:
John Noble
Date: February 25, 2019 08:00AM
Hi folks,
I have a sproc as follows....
CREATE DEFINER=`root`@`localhost` PROCEDURE `usp_AgedDebtorsInsert`(
IN p_Year varchar(4))
BEGIN
SET @p_table := CONCAT('agedDebtors', p_Year);
/* Delete previous inserts with todays date */
SET @p_SQL := CONCAT('DELETE FROM ', @p_table, ' WHERE entryDate = ', CURDATE());
prepare stmt from @p_SQL;
execute stmt;
SET @p_SQL := CONCAT('INSERT INTO ', @p_table, ' (entryDate, accountManagerID, AOLP, balance, bankCharges, cash, CCManagerID, conversionRate, countryID, customerID, dateExported, daybook, docType, discount, DOLP, dueDate, groupID, invNum, invoiceCurrency, invoiceDate, net, netWeight, orderRef, payable, paymentStatus, paidToDate, transactionType, vat, boxes, freshFrozen, comment, accountID, dayBookNo)
SELECT curDate(), accountManagerID, AOLP, balance, bankCharges, cash, CCManagerID, conversionRate, countryID, customerID, dateExported, daybook, docType, discount, DOLP, dueDate, groupID, invNum, invoiceCurrency, invoiceDate, net, netWeight, orderRef, payable, paymentStatus, paidToDate, transactionType, vat, boxes, freshFrozen, comment, accountID, dayBookNo
FROM salesLedger WHERE balance <> 0 ORDER BY salesledger.customerID, invNum');
prepare stmt from @p_SQL;
execute stmt;
END
The second part of work (The insert) works fine. I just cant get the deletion to work at the beginning. The date I am inserting into the [entryDate] field is CURDATE(). But when I try to delete using the same CURDATE(), it does not delete anything ???
Any ideas ?
John