• I'm not clear on why you have three tables with what appears to be the same data, but it sounds to me as though it would make sense to create a table of summarized data, then use that for various reporting purposes. Periodically you would delete (or truncate) the table and re-populate it. You would want to populate it with something like this:

    select type, br, sum(bibal), count(*)

    from <table>

    group by type, br

    That would give you balance totals and counts by branch and type. You could either use the summary table directly for reporting, or summarize it further for totals by branch (across all types) or type (across all branches). This type of approach is commonly used in financial reporting applications -- the data might be refreshed monthly. For a financial institution, you might want to refresh the data daily (overnight).

    This approach makes sense if the volume of data is very large (so you don't want to be re-querying the raw data many times) and it's OK if the data is as of a particular point in time (like last night, or last month). If the volume of data isn't too large, or you need to have current, real-time results, then the summary-table approach would not make sense. In that case, you probably want to create a couple of stored procedures with parameters for the branch or type, so they are not hard-coded. Two or three stored procs would probably cover most of it -- no way you should need twenty of them.

    Doug