用like语句
名称:=名称;
规格:=规格;
开始时间:=开始时间;
..
..
adoquery.sql.add('select * from table where 名称 like '+''''+'%'+名称+'%'+''''+' and 规格 like '+''''+'%'+规格+'%'+''''....
就可以了

解决方案 »

  1.   

    像上面这相就算名称或规格为空的话就认为是全部,至于时间你可以要最后加上 and tabledate between 开始时间 and 结束时间
      

  2.   

    这个SQL并不算太复杂。
    问题是库存数只能是一个点。
    你是要当前的库存数(20010920),还是20000910,还是20010910。
    知道了这个,就可以写了。
    要用到SELECT的嵌套。
      

  3.   

    不知你具体的查询要求是什么,但通过union是可以做到了。我把我原先写的查询库存清单语句让你参考一下吧。
    select c.goodscode,e.goodsname,c.amount
    from workthingscode e,
    (select goodscode,sum(amount) amount
     from
       (select a.goodscode,a.amount,a.indate dd
          from workthingsin a
        union
        select b.goodscode,-b.amount,b.outdate dd
          from workthingsout b
        order by goodscode,dd)
     group by goodscode) c
    where c.goodscode=e.goodscode
      

  4.   

    至于查询条件,那是简单小事。
    我可以帮你的。
    [email protected]
      

  5.   

    clacklin(海风)的语句是对的。
    查出的库存数是当前20010920的库存数。
      

  6.   

    if name = '' then
      name := '%';
    if date1 = '' then
      date1 :='1900-01-01';
    if date2 = '' then
      date2 :='2099-12-31';
     
    strSQL := 'select inv.name,inv.qty,in.count,out.count from in,out,inv where inv.name like '''+name +''' and' (out.date between '+datetostr(date1) + ' and'
    + datetostr(date2) +') +'and (in.date between '+datetostr(date1) + ' and'
    + datetostr(date2) +') where in.name = out.name and in.name = inv.name and out.name = inv.name';
      

  7.   

    或者动态添加条件
    if con1 then
      strSQL := strSQL + str_con1;
    if con2 then
      strSQL := strSQL + str_con2;

    最后加上 and 1=1
      

  8.   

    select temp1.mc,temp1.csum,temp2.rsum
      
    from (mc,sum(chukjs) csum from chuk where rq >= :rq1 and rq <= :rq2 group by mc) temp1,
    (mc,sum(rukjs) rsum from ruk where rq >= :rq1 and rq <= :rp2 group by mc) temp2where temp1.mc = :mc
    and temp2.mc = temp1.mc日期格式没有定义,
    库存数没有求
    名称、规格缩小范围,或不选查询全部 好像要写三个Sql