关于条件组合的语句,求助!

realjoshzuo 2005-08-18 10:07:50
select * from tables where 。。。
共有多个可选的条件:

(A or B) and C and D and e


用户可以随机选择上面的组合


怎样用判断语句来组合上面,如果用IF的话组合实在太多了
有什么好的办法来实现?
谢谢
...全文
61 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
TomyGuan 2005-08-18
  • 打赏
  • 举报
回复
定義一個變量。每次都加上去。

樓上正解 ̄!
xiaobird1 2005-08-18
  • 打赏
  • 举报
回复
strSql = "select * from tables"
strBkSql = "select * from tables"

if A <> "" then
strSql = strSql & " where fldA=" & A
end if

'// 判断strSql是否发生改变,如果改变以后用and连接,否则用where
if B <> "" then
if strSql = strBkSql then
strSql = strSql & " where fldB=" & B
else
strSql = strSql & " and fldB=" & B
end if
end if

'// 后面所有条件与B相同
jingxiaoping 2005-08-18
  • 打赏
  • 举报
回复
可以用

sql="select * from tables where 1=1"
if a or b<>"" then
sql=sql&" and (a or b)"
end if
if c<>"" then
sql=sql&" and c"
end if
if d<>"" then
sql=sql&" and d"
end if
if e<>"" then
sql=sql&" and e"
end if

依次类推

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧