query1的sql语句有
1)select isnull(a.indate,b.outdate)date,IBid,InItem,INinfo,OBid,outitem,outinfo from inbill a full join outbill b on a.indate=b.outdate
2)str:='select isnull(a.indate,b.outdate)date,Initem,INmoney,Outitem,outmoney from inbill a full join outbill b on a.indate=b.outdate where year(indate)between';
    str:=str+inttostr(year1)+' and '+inttostr(year2)+' and month(indate) between '+inttostr(month1)+' and '+inttostr(month2);
    str:=str+'or year(outdate) between'+inttostr(year1)+' and '+inttostr(year2)+' and month(outdate) between '+inttostr(month1)+' and '+inttostr(month2);
    str:=str+'and a.username='''+frm_load.edt_username.Text+''' or b.username='''+frm_load.edt_username.Text+'''';
3)str:='select isnull(a.indate,b.outdate)date,Initem,INmoney,Outitem,outmoney from inbill a full join outbill b on a.indate=b.outdate where indate';
    str:=str+'>='''+edt_date1.Text+''' and indate<='''+edt_date2.Text+'''';
    str:=str+'or outdate>='''+edt_date1.Text+''' and outdate<='''+edt_date2.Text+'''';
    str:=str+'and a.username='''+frm_load.edt_username.Text+''' or b.username='''+frm_load.edt_username.Text+'''';
4)str:='select isnull(a.indate,b.outdate)date,Initem,INmoney,Outitem,outmoney from inbill a full join outbill b on a.indate=b.outdate';
  str:=str+'where a.username='''+frm_load.edt_username.Text+''' or b.username='''+frm_load.edt_username.Text+'''';
query2的sql语句有
1) select * from inbill
2) str:='SELECT   DISTINCT   isnull(year(a.indate),year(b.outdate))col FROM inbill a full join outbill b on a.indate=b.outdate';
str:=str+'where a.username='''+frm_load.edt_username.Text+''' or b.username='''+frm_load.edt_username.Text+'''';
报错说sql语法错误:'a'附近有语法错误但我查了很久都没找到,变成sql语句在查询分析器里也可以运行,这是怎么回事,高手帮帮忙

解决方案 »

  1.   

    2) str:='SELECT DISTINCT isnull(year(a.indate),year(b.outdate))col FROM inbill a full join outbill b on a.indate=b.outdate';
    str:=str+'where a.username='''+frm_load.edt_username.Text+''' or b.username='''+frm_load.edt_username.Text+'''';// str:= str+'where  // 这里没有空格 即 str+' where...你可以把全部SQL语句在执行前,插入到MEMO里来排错 memo1.line.append(adoquery1.sql.text)
      

  2.   

    使用ShowMessage(SQL);
    执行前将SQL语句显示出来,可以即时检查在哪儿有错。