I have the following query to show profit and loss data for the year in my application for expensesselect sum(expenses.amount) as tot, month(expenses.expense_date) as monthfrom expense_categories inner join expenses on expense_categories.id = expenses.main_catidwhere expenses.expense_date between '2009/01/01' and '2009/12/31'group by month(expenses.expense_date)
But.... here is my problem. I have another date field in the expenses table called paid_date. If the paid_date field is a date and not NULL (it can sometimes be null), I want the query to be this insteadselect sum(expenses.amount) as tot, month(expenses.paid_date) as monthfrom expense_categories inner join expenses on expense_categories.id = expenses.main_catidwhere expenses.paid_date between '2009/01/01' and '2009/12/31'group by month(expenses.paid_date)
This query brings 100's of results back but I can't get it to work incorporating both of them.Hope that makes sense?