不是字段名变量来的哦!是一个搜索条件来的啊!

解决方案 »

  1.   

    把存储过程写成下面就行了!
    set @strSQL='
    select employee.EM_NO,employee.name,job.job_name,
    isnull(CC.TC_SUM_SV,0) as TC_SUM_SV,isnull(CC.DO_SUM_SV,0) as DO_SUM_SV,
    isnull(CC.TC_SUM_DG,0) as TC_SUM_DG,isnull(CC.DO_SUM_DG,0) as DO_SUM_DG,
    isnull(TC_JS,0) as TC_JS,
    TC_SUM=isnull((TC_SUM_SV+TC_SUM_DG+TC_JS),0) from
    (select AA.*, BB.JS_money as TC_JS from (
    select EM_ID,
    TC_SUM_SV=sum(case when unit=''分钟'' or unit=''次'' then TC_Money else 0 end),
    DO_SUM_SV=sum(case when unit=''分钟'' or unit=''次'' then DO_Money else 0 end),
    TC_SUM_DG=sum(case when unit<>''分钟'' and unit<>''次'' then TC_Money else 0 end),
    DO_SUM_DG=sum(case when unit<>''分钟'' and unit<>''次'' then DO_Money else 0 end)
    from TC_Do_All
    where '+@timeterm+'
    group by EM_ID) as AA 
    left outer join (
    select JS_EM_ID,JS_Money=sum(JS_Money) 
    from dan 
    where '+@timeterm+'
    group by JS_EM_ID) as BB 
    on AA.EM_ID=BB.JS_EM_ID) as CC right outer join employee on employee.EM_ID=CC.EM_ID left outer join job on employee.job_id=job.job_id order by employee.EM_NO '
    exec(@strSQL)