2017-01-18 3 views
-1

なぜこのエラーが発生するのかわかりません。私は間違いなく "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 
; 
+0

は、CTEで命名されています。最初の行を見てください。 –

答えて

3

があなたのクエリでの問題のいくつかがある「マルチパートの列がバインドできませんでした」と言う:

  1. ラインd..COMGANDA) as "COM G&A",余分な閉じ括弧と余分を持っていますドット;余分なandを持ってc.program = @project and

  2. ライン。

  3. 複数の行は余分なドット(例:d..COMGANDA)を持っています。それは単一のドットd.COMGANDAでなければなりません。

あなたは共通テーブル式が定義されているがエラーを使わないで上記の問題を解決すると消えます。列@dfundako

+1

最初の行には、行頭に2番目のピリオドもあります。 –

+0

ありがとう、それだった! – user2378895

+0

@ user2378895お手伝いできることを楽しみにしています。あなたがチャンスを取ったときにこれを答えとしてマークしてください。 – wdosanjos

関連する問題