J
John
I have a query that uses a subquery to calculate a prior period cost, so I
can calculate the difference between a total todate cost this month and the
total do date cost last month, giving me the period cost. The query works
great! Here's the code:
SELECT tblMonthly.act, tblProjInfo.Period, tblMonthly.adesc,
tblMonthly.pcompl_td, tblMonthly.budgt_cur, tblMonthly.ebudgt_td,
tblMonthly.actualttd, [tblMonthly].[actualttd]-IIf(IsNull((SELECT TOP 1
tblDupe.actualttd FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act)),0,(SELECT TOP 1 tblDupe.actualttd FROM tblMonthly AS
tblDupe WHERE tblDupe.act = tblMonthly.act AND tblDupe.FnDte <
tblMonthly.FnDte ORDER BY tblDupe.FnDte Desc, tblDupe.act)) AS ThisPrdCst
FROM (tblMonthly LEFT JOIN tblActMap ON tblMonthly.act = tblActMap.Act) LEFT
JOIN tblProjInfo ON tblMonthly.FnDte = tblProjInfo.Period_Dte
ORDER BY tblMonthly.act, tblProjInfo.Period;
The IIF statment replaces a null value with a 0 (zero) so the difference
between the two monthly values will give me a true monthly cost.
What I need is a crosstab query that shows all the Activity (tblMonthly.act)
as a row heading, the period (tblProjInfo.Period) as the column headings, and
ThisPrdCst as the values that intersect each Activity ID and Period. I tried
several different approaches and keep getting an error. My suspission is
that subqueries can't be used in a crosstab. Is this correct? (please say
NO!!!)
Any help would be appreciated. What I would like to see as final output:
Act (GroupBy), last(adescr), last(pcompl_td), last(budgt_cur),
last(ebudgt_td), last(actualttd), then period1, 2, 3, ... with ThisPrdCst as
the values in the intersection of Act and Period. (There is only one value
so I am not sure what I should use here First, Last, Sum???)
Any help is greatly appreciated!
can calculate the difference between a total todate cost this month and the
total do date cost last month, giving me the period cost. The query works
great! Here's the code:
SELECT tblMonthly.act, tblProjInfo.Period, tblMonthly.adesc,
tblMonthly.pcompl_td, tblMonthly.budgt_cur, tblMonthly.ebudgt_td,
tblMonthly.actualttd, [tblMonthly].[actualttd]-IIf(IsNull((SELECT TOP 1
tblDupe.actualttd FROM tblMonthly AS tblDupe WHERE tblDupe.act =
tblMonthly.act AND tblDupe.FnDte < tblMonthly.FnDte ORDER BY tblDupe.FnDte
Desc, tblDupe.act)),0,(SELECT TOP 1 tblDupe.actualttd FROM tblMonthly AS
tblDupe WHERE tblDupe.act = tblMonthly.act AND tblDupe.FnDte <
tblMonthly.FnDte ORDER BY tblDupe.FnDte Desc, tblDupe.act)) AS ThisPrdCst
FROM (tblMonthly LEFT JOIN tblActMap ON tblMonthly.act = tblActMap.Act) LEFT
JOIN tblProjInfo ON tblMonthly.FnDte = tblProjInfo.Period_Dte
ORDER BY tblMonthly.act, tblProjInfo.Period;
The IIF statment replaces a null value with a 0 (zero) so the difference
between the two monthly values will give me a true monthly cost.
What I need is a crosstab query that shows all the Activity (tblMonthly.act)
as a row heading, the period (tblProjInfo.Period) as the column headings, and
ThisPrdCst as the values that intersect each Activity ID and Period. I tried
several different approaches and keep getting an error. My suspission is
that subqueries can't be used in a crosstab. Is this correct? (please say
NO!!!)
Any help would be appreciated. What I would like to see as final output:
Act (GroupBy), last(adescr), last(pcompl_td), last(budgt_cur),
last(ebudgt_td), last(actualttd), then period1, 2, 3, ... with ThisPrdCst as
the values in the intersection of Act and Period. (There is only one value
so I am not sure what I should use here First, Last, Sum???)
Any help is greatly appreciated!