Sunday, February 19, 2012

Construction of view or sp

I have the following tables:
tblAccount:
-Account
tblAmount:
-ProjectID
-Account
-Amount1
-Amount2
tblOrder:
-OrderID
-ProjectID
-Account
-Amount
tblTransaction:
-TransactionID
-ProjectID
-Account
-Amount
I would like to show all accounts in tblAccount and if there are amount
values on the accounts in the other tables they should be shown next to
the account number. If there are no values in the other tables the
account without value should still be shown.
Which is the best way to do this, a view or sp and with which syntax?
Regards,
SSomething like:
SELECT
ProjectID,
Account,
OrderAmt = isnull(( SELECT sum( Amount ) FROM tblOrder WHERE Account = a.Acc
ount GROUP BY Account ), 0 )
TransAmt = isnull(( SELECT sum( Amount ) FROM tblTransaction WHERE Account =
a.Account GROUP BY Account ), 0 )
FROM tblAmount a
VIEW or Stored Procedure sorta depends upon how you will use this, and how o
ften you will use it.
On Another Note: [tbl] as a table prefix is 'old school'. Actually 3 was
ted keystrokes since they provide no additional value. (Make every keystroke
useful.) You know it is a table because it follows the FROM keyword.
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
<staeri@.gmail.com> wrote in message news:1160455107.932890.296640@.m73g2000cwd.googlegroups.c
om...
>I have the following tables:
>
> tblAccount:
> -Account
>
> tblAmount:
> -ProjectID
> -Account
> -Amount1
> -Amount2
>
> tblOrder:
> -OrderID
> -ProjectID
> -Account
> -Amount
>
> tblTransaction:
> -TransactionID
> -ProjectID
> -Account
> -Amount
>
> I would like to show all accounts in tblAccount and if there are amount
> values on the accounts in the other tables they should be shown next to
> the account number. If there are no values in the other tables the
> account without value should still be shown.
>
> Which is the best way to do this, a view or sp and with which syntax?
>
> Regards,
>
> S
>

No comments:

Post a Comment