sql server mseq:
Hi everyone,
I'm working on a report that gives a summary of data in a sql server
database. The structure of the database is the following:
A company has one to many investments. These investments are for a certain
sector, are of a certain nature and are in a certain state. This gives us a
data model that ressembles this:
tblInvestments has a foreign key for the company, the sector and the state
tables.
Now, the report I have to do is a detail of the investments by sector. For
example, say we have "Primary", "Secondary", and "Manufacturing" as sectors,
the report must look like this:
Total investments for company x : 15
Sector Investments Active Total
invested
Primary 4 3 130
000$
Secondary 3 3 250
000$
Manufacturing 8 6 140
000$
The Investments column is simply a count of the investments for a particular
company. The Active column lists the count of all the investments that are
in the state "Active" and the Total invested is the sum of a field in the
Investments table for only the investments that are active. I've been
struggling for this problem for a while now and I'd like some input. Is
there a way to:
1) Do this in 1 view
2) List all the sectors even if there is no investments (to list a zero for
the other columns)
I tried to do two separate views for the simple total of the investments and
for the count of the investments and the total amount, but I can't get them
back together in one query (one line for each investment).
Any help would be appreciated.
Éric.