How would I make this query output the results for each account number in the table ?
CREATE PROCEDURE [FinalReport] @AccNum nvarchar(50) SET @AccNum=(SELECT DISTINCT(AccountNumber) FROM [Transaction Table]) AS BEGIN SELECT BranchCode, AccountType, Status, (COUNT(BranchCode))AS 'TOTAL COUNT', (SUM (CAST(Amount AS FLOAT))) AS 'Total Amoun' FROM [Transaction Table]WHERE AccountType='Savings' AND Status='Successful' AND BranchCode=@AccNum group by Status, AccountType, BranchCode UNION ALL SELECT BranchCode, AccountType, Status, (COUNT(BranchCode))AS 'TOTAL COUNT', (SUM (CAST(Amount AS FLOAT))) AS 'Total Amoun' FROM [Transaction Table]WHERE AccountType='Cheque' AND Status='Successful' AND BranchCode=@AccNum group by Status, AccountType, BranchCode UNION ALL SELECT BranchCode, AccountType, Status, (COUNT(BranchCode))AS 'TOTAL COUNT', (SUM (CAST(Amount AS FLOAT))) AS 'Total Amoun' FROM [Transaction Table]WHERE AccountType='Savings' AND Status='Disputed' AND BranchCode=@AccNum group by Status, AccountType, BranchCode UNION ALL SELECT BranchCode, AccountType, Status, (COUNT(BranchCode))AS 'TOTAL COUNT', (SUM (CAST(Amount AS FLOAT))) AS 'Total Amoun' FROM [Transaction Table]WHERE AccountType='Cheque' AND Status='Disputed' AND BranchCode=@AccNum group by Status, AccountType, BranchCode UNION ALL SELECT BranchCode, AccountType, Status, (COUNT(BranchCode))AS 'TOTAL COUNT', (SUM (CAST(Amount AS FLOAT))) AS 'Total Amoun' FROM [Transaction Table]WHERE AccountType='Savings' AND Status='Failed' AND BranchCode=@AccNum group by Status, AccountType, BranchCode UNION ALL SELECT BranchCode, AccountType, Status, (COUNT(BranchCode))AS 'TOTAL COUNT', (SUM (CAST(Amount AS FLOAT))) AS 'Total Amoun' FROM [Transaction Table]WHERE AccountType='Cheque' AND Status='Failed' AND BranchCode=@AccNum group by Status, AccountType, BranchCode END