是不是提示数据类型问题?select cast('W5(11)' as varchar(100)) as etclas,right(rtrim(etprod),1),sum(etVAL) from etiliphy where etwhs in (".$whsstr.") and etclas='W5' and etprod like 'W45%-11%' and etqdte=".$edate." group by right(rtrim(etprod),1) order by right(rtrim(etprod),1)union allselect etclas,right(rtrim(etprod),1),sum(etVAL) from etiliphy where etwhs in (".$whsstr.") and etloct in (".$loctstr.") and etqdte='".$edate."' group by etclas,right(rtrim(etprod),1) order by etclas,right(rtrim(etprod),1)

解决方案 »

  1.   

    select 'W5(11)',right(rtrim(etprod),1),sum(etVAL) from etiliphy where etwhs in ('.$whsstr.') and etclas='W5' and etprod like 'W45%-11%' and etqdte='.$edate.' group by right(rtrim(etprod),1) order by 
    right(rtrim(etprod),1)
    union all
    select etclas,right(rtrim(etprod),1),sum(etVAL) from etiliphy where 
    etwhs in ('.$whsstr.') and etloct in ('.$loctstr.') and 
    etqdte='.$edate.' group by etclas,right(rtrim(etprod),1) order by 
    etclas,right(rtrim(etprod),1)
      

  2.   

    服务器: 消息 156,级别 15,状态 1,行 3
    在关键字 'union' 附近有语法错误。还是不行啊!
      

  3.   

    我是在mssql-server2000的查询分析器上试的!
      

  4.   

    select * from (
    select cast('W5(11)' as varchar(100)) as etclas,right(rtrim(etprod),1) as xxx,sum(etVAL) as yyy from etiliphy where etwhs in (".$whsstr.") and etclas='W5' and etprod like 'W45%-11%' and etqdte=".$edate." group by right(rtrim(etprod),1)union allselect etclas,right(rtrim(etprod),1) as xxx,sum(etVAL) as yyy from etiliphy where etwhs in (".$whsstr.") and etloct in (".$loctstr.") and etqdte='".$edate."' group by etclas,right(rtrim(etprod),1)
    ) as x
     order by etclas,xxx
      

  5.   

    select etclas,xxx,yyy from (
    select cast('W5(11)' as varchar(100)) as etclas,right(rtrim(etprod),1) as xxx,sum(etVAL) as yyy,1 as zzz from etiliphy where etwhs in (".$whsstr.") and etclas='W5' and etprod like 'W45%-11%' and etqdte=".$edate." group by right(rtrim(etprod),1)union allselect etclas,right(rtrim(etprod),1) as xxx,sum(etVAL) as yyy,2 as zzz from etiliphy where etwhs in (".$whsstr.") and etloct in (".$loctstr.") and etqdte='".$edate."' group by etclas,right(rtrim(etprod),1)
    ) as x
     order by zzz,etclas,xxx
      

  6.   

    select 'W5(11)',right(rtrim(etprod),1),sum(etVAL) from etiliphy where etwhs in ('.$whsstr.') and etclas='W5' and etprod like 'W45%-11%' and etqdte='.$edate.' group by right(rtrim(etprod),1) order by right(rtrim(etprod),1)union allselect etclas,right(rtrim(etprod),1),sum(etVAL) from etiliphy where etwhs in ('.$whsstr.') and etloct in ('.$loctstr.') and etqdte='.$edate.' group by etclas,right(rtrim(etprod),1) order by etclas,right(rtrim(etprod),1)
      

  7.   

    union 中不能加有排序 order byselect 'W5(11)',right(rtrim(etprod),1),sum(etVAL) from etiliphy 
    where etwhs in ('.$whsstr.') and etclas='W5' and etprod like 'W45%-11%' and etqdte='.$edate.' 
    group by right(rtrim(etprod),1) 
    union allselect etclas,right(rtrim(etprod),1),sum(etVAL) from etiliphy 
    where etwhs in ('.$whsstr.') and etloct in ('.$loctstr.') and etqdte='.$edate.' 
    group by etclas,right(rtrim(etprod),1)