一查询就提示说.关键字 as 附近有语法错误.我看了好几遍.在sql 2000 上也试了都没问题.怎么一到delphi就出错了.
chaxun.sql.Add('a.spdm as 商品代码,jiage as 价格,nianfen as 年份,jjmc as 季节,dlmc as 大类,ppmc as 品牌,dh as 订货,jh as 进货,th as 退货 from vw_item as a ');
    chaxun.sql.Add('left join (select spdm,sum(sl) as jh from spjhdmx where djbh in (select djbh from spjhd)group by spdm) as b on a.spdm=b.spdm');
    chaxun.sql.Add('left join (select spdm,sum(sl) as th from spthdmx where djbh in (select djbh from spthd)group by spdm) as c on a.spdm=c.spdm');
    chaxun.sql.Add('left join (select spdm,sum(sl) as dh from jordermx where djbh in (select djbh from jorder)group by spdm) as d on a.spdm=d.spdm');
    chaxun.sql.Add('where dh is not null or jh is not null or th is not null or dh!=0 or th!=0 or jh!=0');

解决方案 »

  1.   

    设断点把SQL截出来到SQLSERVER中执行看看具体哪出的问题。
      

  2.   

    chaxun.sql.Add时,要留好空格,例如
    chaxun.sql.Add(' a.spdm as 商品代码,jiage as 价格,nianfen as 年份,jjmc as 季节,dlmc as 大类,ppmc as 品牌,dh as 订货,jh as 进货,th as 退货 from vw_item as a '); 
       chaxun.sql.Add(' left join (select spdm,sum(sl) as jh from spjhdmx where djbh in (select djbh from spjhd)group by spdm) as b on a.spdm=b.spdm '); 
        chaxun.sql.Add(' left join (select spdm,sum(sl) as th from spthdmx where djbh in (select djbh from spthd)group by spdm) as c on a.spdm=c.spdm '); 
        chaxun.sql.Add(' left join (select spdm,sum(sl) as dh from jordermx where djbh in (select djbh from jorder)group by spdm) as d on a.spdm=d.spdm '); 
        chaxun.sql.Add(' where dh is not null or jh is not null or th is not null or dh!=0 or th!=0 or jh!=0 '); 
      

  3.   

    你插入的每句sql语句的最前面和最后面都加上一个空格。
      

  4.   

    晕死掉了.是我自己的问题......在a.spdm 前面少了个select ....晕倒.见笑了.不好意思.