I have a report that I need to generate through multiple queries.
Basically, I am using three tables pulling the same fields:
Table #1- cb_nd_daily, Table #2 cc-sv_daily, Table#3-CD_daily.
From these tables, I need to pull the
acct count----->number of accts
What I am doing is I am getting the total dollar amount of checking, savings, and cds for this institution. Once I get the total, I need to run another query that would break down the product type(checking,savings,CD) by different branches. So I wrote 22 queries and here is just an example of them:
1) Here I am getting the total amount of checking deposits this bank has and total number of checking accounts
Select sum(bibal),count(acct) from cb_nd_daily
---- I would then do the same for savings accounts pulling from SV(cb_sv_daily) and CD from (cb_cd_daily)
The next set of queries I have to filter out by either br # or type.
2) select sum(bibal),count(acct) from cb_nd_daily
where br = 291
----here I am getting the toal of checking accounts and amount for branch 291. I would then apply the same filter for savings and cd
3) Select sum(bibal),count(acct) from cb_nd_daily
where br= 291
and type in (52,77)
-----Here I want to pull all accts that are type 52 & 77)
How do I begin to create a stored procedure where the information would populate for the entire institution and then run subquent queries to populate information based on those filters.
I was thinking of creating a table first, do an insert, and summary but kind of lost on how this logic would work. Any assistance will be appreciated. Thanks