Hi,
CREATE PROCEDURE `FindDuplicateExpenses`(IN `strExpenseDate` DATE, IN `strProfile` VARCHAR(50))
NO SQL
SQL SECURITY INVOKER
SELECT
PD.Code,
PD.ExpenseAuthorizedRefAmount,
PD.FullName,
PD.ExpenseDate,
PD.ExpenseNatureID,
PD.Ignore_Expense,
PD.Profile
FROM tblExpenses AS PD,
(SELECT
Profile,
ExpenseAuthorizedRefAmount,
FullName,
ExpenseDate,
ExpenseNatureID
FROM tblExpenses
GROUP BY Profile, ExpenseAuthorizedRefAmount, FullName, ExpenseDate, ExpenseNatureID
HAVING COUNT(*) > 1) AS SUB1
WHERE
PD.ExpenseAuthorizedRefAmount = SUB1.ExpenseAuthorizedRefAmount
AND PD.FullName = SUB1.FullName
AND PD.ExpenseDate = SUB1.ExpenseDate
AND PD.ExpenseNatureID = SUB1.ExpenseNatureID
AND PD.ExpenseAuthorizedRefAmount >0
AND PD.Profile = strProfile
ORDER BY PD.ExpenseAuthorizedRefAmount, PD.FullName
strProfile can be blank, so if it is blank then this AND PD.Profile = strProfile should not be included in the where clause, How do I bypass this?
Cheers
Darren