| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 613 人关注过本帖
标题:多种组合查询
只看楼主 加入收藏
fyqabc
Rank: 1
等 级:新手上路
帖 子:110
专家分:3
注 册:2006-3-4
结帖率:54.55%
收藏
已结贴  问题点数:0 回复次数:1 
多种组合查询
有六个空(文本框), 可以组成多种条件进行查询,写查询代码时,太多了,写得手软,
有没有一种简捷的方式,比如函数或者循环,只要知道有多少个条件,自动生成多种条件查询代码,
谢谢 !
搜索更多相关主题的帖子: 手软 文本框 
2011-09-21 12:41
towering
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:261
专家分:507
注 册:2007-10-9
收藏
得分:10 
这个看起来很复杂,其实也很简单,给你一个我的站的方法,你一看就明白:

程序代码:
Dim title,classid,html,ispic,istop
cat=0
title=Trim(Replace(Request.Form("title"),"'",""))
classid=Request.Form("classid")
html=Trim(Replace(Request.Form("html"),"'",""))
isspe=Request.Form("isspe")
ispic=Request.Form("ispic")
istop=Request.Form("istop")
sql="select  id,title,istop,ispic,isspe,ClassID,filepath,filename from News where "
    if title<>"" then
        sql=sql&" title like '%"&title&"%' "
        cat=1
    end if
    if classid<>"" and cat=1 then
        sql=sql&" and classid = "&classid
        cat=1
    elseif classid<>"" then
        sql=sql&" classid = "&classid
        cat=1
    end if
    if html<>"" and cat=1 then
        sql=sql&" and filename = '"&html&"' "
        cat=1
    elseif html<>"" then
        sql=sql&" filename = '"&html&"' "
        cat=1
    end if
    if isspe<>"" and cat=1 then
        sql=sql&" and isspe = True "
        cat=1
    elseif isspe<>"" then
        sql=sql&" isspe = True "
        cat=1
    end if
    if ispic<>"" and cat=1 then
        sql=sql&" and ispic = True "
        cat=1
    elseif ispic<>"" then
        sql=sql&" ispic = True "
        cat=1
    end if
    if istop<>"" and cat=1 then
        sql=sql&" and istop = True "
        cat=1
    elseif istop<>"" then
        sql=sql&" istop = True "
        cat=1
    end if
    
set rs=server.CreateObject("adodb.recordset")
rs.open sql,conn,1,1


我的ASP小站:http://www./
2011-09-22 09:35
快速回复:多种组合查询
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012791 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved