title: Common table expression defined but not used
body: <p>I can't figure out why I am getting this error. I definitely am trying to use the cte named "dvr_base". You can see in the inner select there is a join on dvr_base with aliad d.  All of the "d." columns in the select say "the multi-part column could not be bound"</p>
  
  <pre><code>    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 &lt;= @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&amp;A",
      d.COMLABOR as "COM Labor",
      d..COMGANDA) as "COM G&amp;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
  ;
  </code></pre>