Sorry about the short explanation, I was swamped and frustrated on
Friday:)
The query gathers information from a table that is based on several
different factors - some put in forms and submitted, some imported
from excel spreadsheets, and some from DTS packages. They all end up
in a table called ScoreCard.
Now, in order to glean any info from this table, the users need to be
able to see how they are doing(actual) vs some measure. In some
cases, it's a budget, in some cases, it's measured against a constant,
etc. From that, they get scores - zero, half credit, or full credit.
If it were that simple, it'd be a piece of cake.
Each of our buildings(47) has their own numbers and I have to compute
it not only on a monthly basis, but on a YTD basis. ie - look at all
of the months together and compare them against the same rules. I
have stored procedures and functions doing a lot of this based on
Business Rules - measure 1 compares actual vs average monthly.
measure 2 compares that month to zero(if it's over, they get no
points)
Doing all of this is not that hard until I have to start doing all of
the calcs for the month and the YTD. Is there a way for me to
calculate the YTDs and store them somewhere? I don't know anything
about cubes, but could one be used for that?
HEre's the stored proc:
select
[PortfolioID] = Portfolios.EnterpriseID, -- not showing
[PortfolioName] = Portfolios.[Name],
e.EnterpriseID, --not showing
[EnterpriseName] = e.[Name],
EnterpriseLevel.[ObjectiveShortName],
EnterpriseLevel.[ObjectiveDescription],
EnterpriseLevel.[MeasureShortName],
EnterpriseLevel.[MeasureDescription],
EnterpriseLevel.[MeasureBusinessRule], --not showing
EnterpriseLevel.[MeasureMeasure1],
EnterpriseLevel.[MeasureMeasure2],
EnterpriseLevel.[EnterpriseMeasure1],
EnterpriseLevel.[EnterpriseMeasure2],
EnterpriseLevel.[EnterpriseScore],
PortfolioLevel.[PortfolioLevelMeasure1],
PortfolioLevel.[PortfolioLevelMeasure2],
PortfolioLevel.[PortfolioLevelScore],
MeasureLevel.[MeasureLevelMeasure1],
MeasureLevel.[MeasureLevelMeasure2],
MeasureLevel.[MeasureLevelScore],
ObjectiveLevel.[ObjectiveLevelScore] --this is coming out wrong
from Enterprise e inner join
Enterprise_View ev on e.EnterpriseID = ev.EnterpriseID inner join
( -- Select only facilities, leave out companies and portfolios
select EnterpriseID,
[Name]
from Enterprise
where (EnterpriseTypeID = 2) and
(EnterpriseID <> 103) --exclude home healthcare
) Portfolios on Portfolios.EnterpriseID = ev.ParentID inner join
( -- Enterprise Level Information
select e.EnterpriseID,
o.[ObjectiveID],
[ObjectiveShortName] = o.[ShortName],
[ObjectiveDescription] = o.[Description],
[MeasureShortName] = m.[ShortName],
[MeasureDescription] = m.[Description],
[MeasureBusinessRule] = m.[BusinessRule],
[MeasureMeasure1] = m.[Measure1],
[MeasureMeasure2] = m.[Measure2],
m.MeasureID,
m.[PartialScore],
[EnterpriseMeasure1] = sc.[Measure1],
[EnterpriseMeasure2] = sc.[Measure2],
[EnterpriseScore] = dbo.udfn_M1vsM2(sc.Measure1, sc.Measure2,m.
[PartialScore], m.BusinessRule, m.Score)
from ScoreCard sc inner join
Enterprise e on sc.EnterpriseID = e.EnterpriseID inner join
Measure m on sc.MeasureID = m.MeasureID inner join
Objective o on m.ObjectiveID = o.ObjectiveID
where (sc.[Year] = @Year) and
(sc.[Month] = @Month)
) EnterpriseLevel on EnterpriseLevel.EnterpriseID = e.EnterpriseID
inner join
( -- Measure Level Information
select m.MeasureID,
[MeasureLevelMeasure1] = sum(sc.[Measure1]),
[MeasureLevelMeasure2] = sum(sc.[Measure2]),
[MeasureLevelScore] = dbo.udfn_M1vsM2(sum(sc.[Measure1]), sum(sc.
[Measure2]),max(m.[PartialScore]), max(m.BusinessRule), max(m.Score))
from ScoreCard sc inner join
Measure m on sc.MeasureID = m.MeasureID
where (sc.[Year] = @Year) and
(sc.[Month] = @Month)
group by m.MeasureID
) MeasureLevel on MeasureLevel.MeasureID = EnterpriseLevel.MeasureID
inner join
( --Portfolio Level information
select [PortfolioID] = Portfolios.EnterpriseID,
m.MeasureID,
[PortfolioLevelMeasure1] = sum(sc.[Measure1]),
[PortfolioLevelMeasure2] = sum(sc.[Measure2]),
[PortfolioLevelScore] = dbo.udfn_M1vsM2(sum(sc.Measure1),
sum(sc.Measure2),max(m.[PartialScore]), max(m.BusinessRule),
max(m.Score))
from ScoreCard sc inner join
Enterprise e on sc.EnterpriseID = e.EnterpriseID inner join
Enterprise_View ev on e.EnterpriseID = ev.EnterpriseID inner join
( -- Select only facilities, leave out companies and portfolios and
homehealthcare
select EnterpriseID
from Enterprise
where (EnterpriseTypeID = 2) and
(EnterpriseID <> 103) --exclude home healthcare)
) Portfolios on Portfolios.EnterpriseID = ev.ParentID inner join
Measure m on sc.MeasureID = m.MeasureID
where (sc.[Year] = @Year) and
(sc.[Month] = @Month)
group by Portfolios.EnterpriseID,
m.[MeasureID]
) PortfolioLevel on PortfolioLevel.PortfolioID =
Portfolios.EnterpriseID and
PortfolioLevel.MeasureID = EnterpriseLevel.MeasureID inner join
( -- Objective Level information
--score by **objective** == all meaures in that objective added for
all facilities
select m.ObjectiveID,
ObjectiveLevelScore = sum(MeasureTotals.Score)
from Measure m inner join
(
select m.MeasureID,
Score = dbo.udfn_M1vsM2(sum(sc.measure1), sum(sc.measure2),max(m.
[PartialScore]), max(m.businessrule), max(m.score))
from Enterprise e inner join
ScoreCard sc on sc.EnterpriseID = e.EnterpriseID inner join
Measure m on sc.MeasureID = m.MeasureID
where (e.EnterpriseTypeID = 3) and
(e.EnterpriseID <> 103) and--exclude home healthcare
(sc.[Year] = @Year) and
(sc.[Month] = @Month)
group by m.MeasureID
) MeasureTotals on m.MeasureID = MeasureTotals.MeasureID
group by m.ObjectiveID
) ObjectiveLevel on ObjectiveLevel.ObjectiveID =
EnterpriseLevel.ObjectiveID
order by [PortfolioName], EnterpriseLevel.[MeasureShortName],
[EnterpriseName]
On Sep 15, 5:36 am, Hugo Kornelis
[quoted text, click to view] <h...@perFact.REMOVETHIS.info.INVALID> wrote:
> On Fri, 14 Sep 2007 23:10:30 -0000, M@ wrote:
> >I have information that people put in once a month, that I would like
> >to report on periodically.
>
> >I tried doing sums in a function, but it takes a long time. Are there
> >any recommended ways of storing it periodically, or creating a view?
>
> Hi M@,
>
> If you frequently query on aggregated data that changes infrequently,
> you can consider using an indexed view. These are described in Books
> Online, along with their (many!) limitations.
>
> Since your question is very vague, my answer can't be more specific
> thann this.
>
> --
> Hugo Kornelis, SQL Server MVP
> My SQL Server blog:
http://sqlblog.com/blogs/hugo_kornelis