我在SQL中用了下面一条语句:
SQL.Add('select yg.bm,yg.xm,yg.kh,kq.rq,kq.sj from kq where rq>#'+strdate1+'#' +'and rq<#'+ strdate2+'#' +'and kh in (select * from yg where kq.kh=yg.kh and bm='''+ComboBox1.Text+''' and xm='''+ComboBox2.Text+''')order by sj');
   提示SQL语句中的子查询不能返回多个值,只能返回一个值。
   而用下面一条语句则,只能查到kh和sj两个字段,这该怎么改正呢?
SQL.Add('select yg.bm,yg.xm,yg.kh,kq.rq,kq.sj from yg,kq where rq>#'+strdate1+'#' +'and rq<#'+ strdate2+'#' +'and kq.kh=yg.kh and bm='''+ComboBox1.Text+''' and xm='''+ComboBox2.Text+''')order by sj');

解决方案 »

  1.   

    SQL.Add('select yg.bm,yg.xm,yg.kh,kq.rq,kq.sj from kq where rq>#'+strdate1+'#' +'and rq<#'+ strdate2+'#' +'and kh in (select kq.kh from yg where kq.kh=yg.kh and bm='''+ComboBox1.Text+''' and xm='''+ComboBox2.Text+''')order by sj');
      

  2.   

    SQL.Add('select yg.bm,yg.xm,yg.kh,kq.rq,kq.sj from kq where rq>#'+strdate1+'#' +'and rq<#'+ strdate2+'#' +'and kh in (select * from yg where kq.kh=yg.kh and bm='''+ComboBox1.Text+''' and xm='''+ComboBox2.Text+''')order by sj');改成
    SQL.Add('select yg.bm,yg.xm,yg.kh,kq.rq,kq.sj from kq where rq>#'+strdate1+'#' +'and rq<#'+ strdate2+'#' +'and kh in (select kh from yg where kq.kh=yg.kh and bm='''+ComboBox1.Text+''' and xm='''+ComboBox2.Text+''')order by sj');
       
      

  3.   

    我的表结构是这样的:表kq有字段:kh,rq,sj
                           表yg有字段:bm,xm,kh
       而我是所有字段都要啊,所以得两个表能过kh联起来,因为kq这个表中字段的值是从机子上读出来的,所以没办法改!