なぜこのエラーが発生するのかわかりません。私は間違いなく "dvr_base"という名前のcteを使用しようとしています。インナーセレクトには、dvr_baseとaliadの結合があります。すべての "d"。選択中の列が共通テーブル式が定義されていますが使用されていません
with dvr_base (program, cawpid, cecode, costrep, period, hours, direct, overhead, mhxdev, plwdev, ganda, comlabor, comganda, tcost)
as
(
select
program,
cawpid,
cecode,
costset,
right('0000' + cast(datepart(year, pd_finish) as varchar(4)), 4) + right('00' + cast(datepart(month, pd_finish) as varchar(2)), 2),
sum(hours),
sum(direct),
sum(overhead),
sum(mhxdev),
sum(plwdev),
sum(ganda),
sum(COMLABOR),
sum(COMGANDA),
sum(direct+overhead+mhxdev+plwdev+ganda+comlabor+comganda)
from
tphase join costdetl u on tphase.class = u.class and u.instance = @costdetlid
join rcutoff r on tphase.df_date between r.pd_start and r.pd_finish
where
tphase.program = @project and
tphase.df_date <= @statusdate and
r.instance = @cutoffid
group by
tphase.program,
tphase.cawpid,
tphase.cecode,
u.costset,
r.pd_finish
)
select
c.program as ProjectID,
c.ca3 as "Control Acct",
c.descrip as "Control Acct Description",
c.ca2 as OBS,
c.ca1 as WBS,
d.cecode as Resource,
w.d1 as "Resource Type",
d.costrep as "Cost Type",
d.period as "YYYYMM",
d.hours as Hours,
d.direct as Direct,
d.overhead as Overhead,
d.mhxdev as MHX,
d..plwdev as PLW,
d..ganda as "G&A",
d.COMLABOR as "COM Labor",
d..COMGANDA) as "COM G&A",
d.tcost as "Total Cost"
from
cawp c join dvr_base d on
c.program = d.program and c.cawpid = d.cawpid
join calcdesc w on d.cecode = w.cecode and w.calcfile = @calcfile
where
c.program = @project and
order by
c.program,
c.ca3,
c.descrip,
c.ca2,
c.ca1,
d.cecode,
w.d1,
d.period
;
は、CTEで命名されています。最初の行を見てください。 –