标题:条件语句嵌套请教
只看楼主
s6gy
Rank: 1
等 级:新手上路
帖 子:330
专家分:0
注 册:2006-10-26
 问题点数:0 回复次数:1 
条件语句嵌套请教

if Session("UserName") = "user" or Session("UserName") ="admin" then
sql ="Select * From bzglsw where jsc<>'2' order by id desc"
else if sql_where="" then
sql ="Select * From bzglsw where jsc<>'2' order by id desc"
else
sql ="Select * From bzglsw "&sql_where&" and jsc<>'2' order by id desc"
end if
sql ="Select * From bzglsw where jsc<>'2'and userid= '"&Session("UserID")&"' order by id desc"
end if
不能实现中间的要求if sql_where="" then
sql ="Select * From bzglsw where jsc<>'2' order by id desc"
else
sql ="Select * From bzglsw "&sql_where&" and jsc<>'2' order by id desc"
end if
如果把 中间那个end if 放到最后也就是二个END IF在一起就不能实现 sql ="Select * From bzglsw where jsc<>'2'and userid= '"&Session("UserID")&"' order by id desc"
请问如何写
谢谢各位 请指教 语句无错误只需告诉我如何同时实现2个功能就可以了

搜索更多相关主题的帖子: 嵌套 语句 sql order 
2006-11-30 12:49
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
得分:0 

if Session("UserName") = "user" or Session("UserName") ="admin" then
sql ="Select * From bzglsw where jsc<>'2' order by id desc"
else
if sql_where="" then
sql ="Select * From bzglsw where jsc<>'2' order by id desc"
else
sql ="Select * From bzglsw "&sql_where&" and jsc<>'2' order by id desc"
end if
sql ="Select * From bzglsw where jsc<>'2'and userid= '"&Session("UserID")&"' order by id desc"
end if
按照现在的结构,Session("UserName") = "user" or Session("UserName") ="admin"满足这两个条件其中之一就会执行
sql ="Select * From bzglsw where jsc<>'2' order by id desc"
这句话,因为OR是或者的关系。而执行else必须Session("UserName") = "user" or Session("UserName") ="admin"两个条件都不满足才会执行else。

2006-11-30 14:15



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




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

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