首页   |   IT资讯   |   综合资讯   |   开发   |   软件   |   问答   |   网络技术   |   网络综合
更多:
当前位置:首页 » 手机数码
文章正文

满足多个条件的查询,应该怎么做呢?!

类型:转载   责任编辑:asp   日期:2007/03/01

    

本人用sql语句,加上if的判断条件来做的。在多个combobox中选择选项,以此(所选的项)做为条件,然后通过单击按钮来实现符合多个条件的或一个条件的查询,结果符合条件的记录显示在dbgrid中。  
      但在做当其中任何一个或多个combobox中为空值时(就是没有做出选择时),如何让sql语句来实现:不去读取该空值而继续判断已经做出选择的combobox,从而显示出符合条件的记录.  
      或是如果你有好的方法来完成多个条件的查询,也劳架你帮帮我,好吗?谢谢!!!!

推荐阅读

  • 英特尔宣布停产多款FSB800 Xeon处理器 [详细内容]
  • 整低5千 戴尔POWEREDGE 2800很便宜 [详细内容]
  • 狂降千元 索尼笔记本带光驱1.26KG [详细内容]
  • 英特尔垄断案预计明年底美国开庭 [详细内容]
  • 浅谈诺基亚8855的进灰和处理 [详细内容]
  • 高性价比彩屏MP3 蓝魔RM910图赏 [详细内容]
  • 寻求新增长来源 英特尔要大力开发新兴市场 [详细内容]
  • 网友回答:
    网友:genphone_ru

    var   sqlstr:   string;  
          sqlstr   :=   select   *   from   tablename   where   1=1   ;  
          if   combobox1.itemindex   <>   -1   then  
              sqlstr   :=   sqlstr   +     and   a=+combobox1.items[combobox1.itemindex]+;  
          if   combobox2.itemindex   <>   -1   then  
              sqlstr   :=   sqlstr   +     and   b=+combobox2.items[combobox2.itemindex]+;  
          .................  
          if   comboboxn.itemindex   <>   -1   then  
              sqlstr   :=   sqlstr   +     and   n=+comboboxn.items[comboboxn.itemindex]+;  
          query1.close;  
          query1.sql.text   :=   sqlstr;  
          query1.open;

    网友:ruixi

    with   query1   do  
          begin  
              close;  
              sql.clear;  
              sql.add(select   *   from   tablename   where   names=大虫子);  
              if   combobox1.text<>   then    
                  sql.add(and   params1=+combobox1.text+);  
              if   combobox2.text<>   then    
                  sql.add(and   params2=+combobox2.text+);  
              if   combobox3.text<>   then    
                  sql.add(and   params3=+combobox3.text+);  
              if   combobox4.text<>   then    
                  sql.add(and   params4=+combobox4.text+);  
           
                          .......    
              open;  
          end;

    网友:lisen101

    另:还可以给变量设置   初始值,sql语句为固定式的!如果,该combobox.text为空,则取默认值。比如:     aa   between       and   zz  
     

    .
    站内导航:
    IT热门资讯:
      最佳浏览:1024X768 MSIE
    ©2007 jqmk.com.cn All Rights Reserved