Try this command, assuming you found that week() and hour() worked. Only one half of the union all statement will execute based on the type of hours chosen by parameter, so only one SQL expression will need to be compiled--should make this faster. The order by clause belongs at the end of the entire statement only. I added a "field" called "DateType" that you can use to see what type of dates are being pulled.
SELECT "HQCO"."Name",
"JCCD"."JCCo",
"JCCD"."Job",
"JCCD"."PhaseGroup",
"JCCD"."Phase",
"JCCD"."CostType",
"JCJP"."Description",
"JCCD"."UM",
"JCCD"."EstUnits",
"JCCD"."ActualUnits",
"JCCD"."EstHours",
"JCCD"."ActualHours",
"JCCD"."ActualDate",
"JCJM"."Description",
"JCCH"."UM",
"JCCH"."PhaseUnitFlag",
"JCCD"."PostedDate",
"JCCD"."ActualCost",
"JCCD"."EstCost",
"JCCD"."ProjCost",
"JCCD"."ProjUnits",
"JCCD"."ForecastCost",
"JCCH"."CostType",
"JCCH"."ActiveYN",
"JCJP"."ActiveYN",
'Actual Date' "DateType",
(
select sum(a."ActualHours")
from "JCCD" a
where a."Employee" ="JCCD"."Employee" and
a."Phase" = Left("JCCD"."Phase",2 ) and
WEEK(a."ActualDate")=WEEK("JCCD"."ActualDate") and
YEAR(a."ActualDate")=YEAR("JCCD"."ActualDate")
) "sumamtactualdt"
FROM ((("Viewpoint"."dbo"."JCCD" "JCCD"
INNER JOIN "Viewpoint"."dbo"."JCJM" "JCJM" ON
("JCCD"."JCCo"="JCJM"."JCCo") AND
("JCCD"."Job"="JCJM"."Job") and
(
"JCCD"."CostType" = {?LaborCT} and
"JCCD"."Phase" >= '{?BegPhase}' and
"JCCD"."Phase" <= '{?EndPhase}' and
"JCCD"."Job" = '{?EndJob}' and
"JCCD"."JCCo"= {?Company} and
'{?DateOption}' = 'A' and
"JCCD"."ActualDate"<= {?EndWklyDate}
)
)
INNER JOIN "Viewpoint"."dbo"."JCJP" "JCJP" ON
((("JCCD"."JCCo"="JCJP"."JCCo") AND
("JCCD"."Job"="JCJP"."Job")) AND
("JCCD"."PhaseGroup"="JCJP"."PhaseGroup")) AND
("JCCD"."Phase"="JCJP"."Phase")
)
INNER JOIN "Viewpoint"."dbo"."HQCO" "HQCO" ON
"JCCD"."JCCo"="HQCO"."HQCo"
)
LEFT OUTER JOIN "Viewpoint"."dbo"."JCCH" "JCCH" ON
(((("JCCD"."JCCo"="JCCH"."JCCo") AND
("JCCD"."Job"="JCCH"."Job")) AND
("JCCD"."PhaseGroup"="JCCH"."PhaseGroup")) AND
("JCCD"."Phase"="JCCH"."Phase")) AND
("JCCD"."CostType"="JCCH"."CostType")
union all
SELECT "HQCO"."Name",
"JCCD"."JCCo",
"JCCD"."Job",
"JCCD"."PhaseGroup",
"JCCD"."Phase",
"JCCD"."CostType",
"JCJP"."Description",
"JCCD"."UM",
"JCCD"."EstUnits",
"JCCD"."ActualUnits",
"JCCD"."EstHours",
"JCCD"."ActualHours",
"JCCD"."ActualDate",
"JCJM"."Description",
"JCCH"."UM",
"JCCH"."PhaseUnitFlag",
"JCCD"."PostedDate",
"JCCD"."ActualCost",
"JCCD"."EstCost",
"JCCD"."ProjCost",
"JCCD"."ProjUnits",
"JCCD"."ForecastCost",
"JCCH"."CostType",
"JCCH"."ActiveYN",
"JCJP"."ActiveYN",
'Posted Date' "DateType",
(
select sum(a."ActualHours")
from "JCCD" a
where a."Employee" ="JCCD"."Employee" and
a."Phase" = Left("JCCD"."Phase",2 ) and
WEEK(a."PostedDate")=WEEK("JCCD"."PostedDate") and
YEAR(a."PostedDate")=YEAR("JCCD"."PostedDate")
) "sumamtposteddt"
FROM ((("Viewpoint"."dbo"."JCCD" "JCCD"
INNER JOIN "Viewpoint"."dbo"."JCJM" "JCJM" ON
("JCCD"."JCCo"="JCJM"."JCCo") AND
("JCCD"."Job"="JCJM"."Job") and
(
"JCCD"."CostType" = {?LaborCT} and
"JCCD"."Phase" >= '{?BegPhase}' and
"JCCD"."Phase" <= '{?EndPhase}' and
"JCCD"."Job" = '{?EndJob}' and
"JCCD"."JCCo"= {?Company} and
'{?DateOption}' = 'P'and
"JCCD"."PostedDate" <= {?EndWklyDate}
)
)
INNER JOIN "Viewpoint"."dbo"."JCJP" "JCJP" ON
((("JCCD"."JCCo"="JCJP"."JCCo") AND
("JCCD"."Job"="JCJP"."Job")) AND
("JCCD"."PhaseGroup"="JCJP"."PhaseGroup")) AND
("JCCD"."Phase"="JCJP"."Phase")
)
INNER JOIN "Viewpoint"."dbo"."HQCO" "HQCO" ON
"JCCD"."JCCo"="HQCO"."HQCo"
)
LEFT OUTER JOIN "Viewpoint"."dbo"."JCCH" "JCCH" ON
(((("JCCD"."JCCo"="JCCH"."JCCo") AND
("JCCD"."Job"="JCCH"."Job")) AND
("JCCD"."PhaseGroup"="JCCH"."PhaseGroup")) AND
("JCCD"."Phase"="JCCH"."Phase")) AND
("JCCD"."CostType"="JCCH"."CostType")
ORDER BY 2,3,4
Regarding showing ties, I had been thinking you could use topN and include ties, but that option isn't available within a crosstab. You could easily do a vertical display by week. Or you could create a manual crosstab. What is the maximum number of weeks you would want to show in a crosstab?
-LB