标题:多条件查询语句用asp怎么写?等待ing
只看楼主
bonsaicheung
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-4-24
 问题点数:0 回复次数:7 
多条件查询语句用asp怎么写?等待ing
我想做个多条件查询,大概查询的条件组合有12个
请问应该怎么写,用asp
搜索更多相关主题的帖子: 语句 ing asp 条件 查询 
2007-04-24 16:58
sithing
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-11-30
得分:0 
你说的组合指的是…………?


2007-04-24 17:03
bonsaicheung
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-4-24
得分:0 
可以选择得是4个,4个条件也可以组合出来多种情况啊
例如1成立跟3成立得时候,查询出来得列表
2成立和3成立,查询出来列表
这些都不一样,请问应该怎么写呢
2007-04-24 17:17
在编程中沦落
Rank: 2
等 级:新手上路
威 望:4
帖 子:411
专家分:0
注 册:2005-12-25
得分:0 
用select CASE吧…………

看看我这个例子就明白了…………

你设定好你参数的传递和接收的值就行了…………

sea =request("sea")
Select Case sea

Case "diqu"

Rs.Source = "SELECT * FROM admin WHERE diqu like '%" + Replace(Rs__Keyword, "'", "''") + "%' ORDER BY id DESC"

Case "Gbz"

Rs.Source = "SELECT * FROM admin WHERE Gbz like '%" + Replace(Rs__Keyword, "'", "''") + "%' ORDER BY id DESC"

Case "Gdate"
Rs.Source = "SELECT * FROM admin WHERE Gadddate like '%" + Replace(Rs__Keyword, "'", "''") + "%' ORDER BY id

Case "Gjscode"

Rs.Source = "SELECT * FROM admin WHERE Gjscode like '%" + Replace(Rs__Keyword, "'", "''") + "%' ORDER BY id DESC"
case else

Rs.Source = "SELECT * FROM admin WHERE Gjscode like '%" + Replace(Rs__Keyword, "'", "''") + "%' ORDER BY id DESC"

end select

2007-04-24 17:34
在编程中沦落
Rank: 2
等 级:新手上路
威 望:4
帖 子:411
专家分:0
注 册:2005-12-25
得分:0 
我上面可用的是组合,如果数量大的时候就比较多代码(只有一个下拉框时比较实用,多个复选框的时候就要考虑的较多),而且漏掉也有可能,最好看能把你表单传递的值设少些…………,或者改一下form的设计…………

2007-04-24 17:36
阳光白雪
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:39
帖 子:2220
专家分:0
注 册:2005-11-18
得分:0 

[QUOTE]''=======查询条件参数========
Dim Condition,FormObj
Condition = " 1=1"
Dim KeyWord,BeginDate,EndDate,IncludeClass,AdminCode,ArtileStatus,TopFlag,VouchFlag,ArticlePic,Special
KeyWord = Request.Form("KeyWord")
BeginDate = Request.Form("BeginDate")
EndDate = Request.Form("EndDate")
IncludeClass = Request.Form("IncludeClass")
AdminCode = Request.Form("AdminCode")
ArtileStatus = Request.Form("ArtileStatus")
TopFlag = Request.Form("TopFlag")
VouchFlag = Request.Form("VouchFlag")
ArticlePic = Request.Form("ArticlePic")
Special = Request.Form("Special")

''判断传递来的参数值是否为空构造SQL查询条件
If KeyWord <> "" Then
Condition = Condition & " And Title like '%"& KeyWord &"%'"
End If
If BeginDate <> "" And IsDate(BeginDate) Then
Condition = Condition & " And PublitTime>='"& BeginDate &" 00:00:00'"
End If
If EndDate <> "" And IsDate(EndDate) Then
Condition = Condition & " And PublitTime<='"& EndDate &" 23:59:59'"
End If
If TopFlag = 1 Then
Condition = Condition & " And TopFlag='1'"
End If
If VouchFlag = 1 Then
Condition = Condition & " And VouchFlag='1'"
End If
If ArticlePic = 1 Then
Condition = Condition & " And ArticlePic<>''"
End If
If Special <> "" Then
Condition = Condition & " And ArticleSubject In("& Special &")"
End If
''===========================
''=========分页参数==========
Dim Page,TurnPageName,LinkStr
Page = Request.QueryString("Page")
TurnPageName = "PageName.Asp" '当前页面名称
LinkStr = ""
If Page = "" Or Not IsNumeric(Page) Then
Page = 1
Session("Condition") = Condition ''将查询条存储在SESSION中
Else
Condition = Session("Condition") ''在SESSION中提取查询条件
End If
''===========================

'构造出完整的SQL语句
SqlStr ="Select * From Article Where"& Condition &" Order By PublisTime Desc"[/QUOTE]


专注于WEB前端交互平台开发:[url=http://blog./]blog.[/url](富客户端技术(RIA)交流平台)
2007-04-24 17:43
rainic
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:2367
专家分:0
注 册:2005-8-9
得分:0 
在PHP中,用数组会很方便,ASP可能也可以考虑用数组或dictionary做一下

2007-04-24 22:07
天上碑
Rank: 1
等 级:新手上路
威 望:1
帖 子:111
专家分:0
注 册:2007-4-23
得分:0 
<%
username=request("username")
phone=request("phone")
sql="select * from [user] where 1=1"

if request("username")<>"" then sql=sql& "and username ='"&username&"' "
if request("phone")<>"" then sql=sql& "and phone='"&phone&"' "
end if
%>

我很郁闷!
2007-04-25 11:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-134553-1-1.html




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

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