I have a table called Transactions with these columns : TransactionDate, DRCR,TransactionValue,AccountNumber
TransactionDate - Date on which a transaction was done
DRCR - Shows whether the transaction was a debit or credit
TransactionValue - How much was transacted
AccountNumber - The client's account number.
My request is to do a Monthly High Low Balance Report.
The report should show Highest Balance(maximum value of credit transactions),Lowest Balance(minimum value of debit transactions),TotalCredits(sum of all credit transactions), TotalDebits(sum of all debit transactions). These will be filtered using Transaction date. A user can select start date as 1 June 2013 and end date as 30 June 2013. So the report should show data filtered to this period.
I tried this query but its filtering to the period specified.
SELECT AccountNumber, (SELECT MAX(transactionvalue) FROM Transactions WHERE (trans_drcrindicatorname = 'Credit') AND (transactionaccount = @AccNumber) AND (transactiondatetime BETWEEN @StartDate AND @EndDate)) AS MAX_CREDIT, (SELECT MIN(transactionvalue) FROM Transactions WHERE (transactiondrcr = 'Debit') AND (transactionaccount = @AccNumber) AND (transactiondatetime BETWEEN @StartDate AND @EndDate)) AS MIN_DEBIT, (SELECT SUM(transactionvalue) FROM Transactions WHERE (transactiondrcr = 'Credit') AND (transactionaccount = @AccNumber) AND (transactiondatetime BETWEEN @StartDate AND @EndDate)) AS TOTAL_CREDITS, (SELECT SUM(transactionvalue) AS Expr1 FROM Transactions WHERE (transactiondrcr = 'Debit') AND (transactionaccount = @AccNumber) AND (transactiondatetime BETWEEN @StartDate AND @EndDate)) AS TOTAL_DEBITS FROM Transactions
Good is not good enough when best is expected !!!