帮忙看看这条查询语句,该如何使它不那么变态?:D

never1234 2003-09-10 03:23:40
最后的语句如下:

Select uID,u1,u2,u3,u4,uDate FROM db_User where 1=1 and u2='男' and u3='正局长' and u4='副局级' and u6='区市县机关' and u7='35岁以下' and u8='11-20年' and u9='5年以下' and u10='2' and u11='研究生' and u12='硕士' and u15='1' and uID in (select uID from db_Zsdc where zType='A' and z2='1' and z3='2') and uID in (select uID from db_Zsdc where zType='B' and z2='2' and z3='3') and uID in (select uID from db_Zsdc where zType='C' and z2='2' and z3='2') and uID in (select uID from db_Zsdc where zType='D' and z2='3' and z3='2') and uID in (select uID from db_Zsdc where zType='E' and z2='2' and z3='2') and uID in (select uID from db_Szdc where sType='A' and s2='2' and s3='2') and uID in (select uID from db_Szdc where sType='B' and s2='3' and s3='2') and uID in (select uID from db_Szdc where sType='C' and s2='3' and s3='2') and uID in (select uID from db_Lw where 1=1 and l3='2' and l4='1' and l5='1') and uID in (select uID from db_Gw where 1=1 and g3='2' and g4='1' and g5='3') and uID in (select uID from db_Zz where z3='2') and uID in (select uID from db_Gl where 1=1 and g2='2' and g3='7') and uID in (select uID from db_Gr where 1=1 and g1='1' and g2='4') order by uID desc

实际运用中,能使它更优化吗?
...全文
44 40 打赏 收藏 转发到动态 举报
写回复
用AI写文章
40 条回复
切换为时间正序
请发表友善的回复…
发表回复
hfwpq 2003-12-31
  • 打赏
  • 举报
回复
同意楼上的意见!这样敷衍了事,后患无穷
zorou_fatal 2003-12-31
  • 打赏
  • 举报
回复
重新设计数据库吧
这样的代码维护和修改起来都够费劲的。
youngqp 2003-12-31
  • 打赏
  • 举报
回复
楼上的,我很佩服你的毅力啦! 写这么多,真是bt呀!
jzywh 2003-12-31
  • 打赏
  • 举报
回复
还不如在 WEB服务器上 判断!
xiaoyuehen 2003-12-31
  • 打赏
  • 举报
回复
我也来再顶一次...反正楼主看来也不打算结贴..

从这么长的代码来看, 人反而显得像一个代码机器了..我很佩服你会为了这么多条件写这么多语句, 很有耐心!

但如果是我的话...我一定会想办法把条件分成几类, 汇总, 再列出相关的..写这么多代码我肯定是不干!
songqzs 2003-12-16
  • 打赏
  • 举报
回复
顶一下!看来有必要解决一下搜索引擎的换代问题了,对于复杂问题提出一种新的方案!
never1234 2003-12-16
  • 打赏
  • 举报
回复
这是最后的语句:
sql = "Select uID,u1,u2,u3,u4,u5,uDate FROM db_User where uID in ("&uIDArr&") order by uID desc"

简还是可以部分简化的,不过,政府的人嘛大家都知道在这方面本来也就是变态的,经常提出加一些莫名其妙异想天开的功能,为了应付这些大脑,还是留一些余地便于操作,反正他们有的是钱。(一台服务器上基本就放这么一个变态的系统)
never1234 2003-12-16
  • 打赏
  • 举报
回复
if search="YES" then
uID=uIDArr
uIDArr=""
dbWhere="where 1=1"

if M(9)="1" then
dbWhere1="where 1=1"
dbWhere1=dbWhere1 & " and (j1<>'' or j2<>'' or j3<>'' or j4<>'' or j5<>'' or j6<>'' or j7<>'')"
dbWhere=dbWhere & " and uID in (select uID from db_Jsj "&dbWhere1&")"
else

if V(55)<>"0" or V(56)<>"0" or V(57)<>"0" or V(58)<>"0" or V(59)<>"0" or V(60)<>"0" or V(61)<>"0" then
dbWhere1="where 1=1"
if V(55)="有" then
dbWhere1=dbWhere1 & " and j1<>''"
elseif V(55)="无" then
dbWhere1=dbWhere1 & " and j1=''"
end if
if V(56)<>"0" then dbWhere1=dbWhere1 & " and j2='" & V(56) & "'"
if V(57)="有" then
dbWhere1=dbWhere1 & " and j3<>''"
elseif V(57)="无" then
dbWhere1=dbWhere1 & " and j3=''"
end if
if V(58)<>"0" then dbWhere1=dbWhere1 & " and j4='" & V(58) & "'"
if V(59)="有" then
dbWhere1=dbWhere1 & " and j5<>''"
elseif V(59)="无" then
dbWhere1=dbWhere1 & " and j5=''"
end if
if V(60)<>"0" then dbWhere1=dbWhere1 & " and j6='" & V(60) & "'"
if V(61)="有" then
dbWhere1=dbWhere1 & " and j7<>''"
elseif V(61)="无" then
dbWhere1=dbWhere1 & " and j7=''"
end if
dbWhere=dbWhere & " and uID in (select uID from db_Jsj "&dbWhere1&")"
end if
end if

if M(10)="1" then
dbWhere1="where 1=1"
dbWhere1=dbWhere1 & " and (w1<>'' or w2<>'' or w3<>'' or w4<>'' or w5<>'' or w6<>'' or w8<>'' or w9<>'' or w11<>'' or w12<>'' or w14<>'' or w15<>'' or w16<>'' or w17<>'')"
dbWhere=dbWhere & " and uID in (select uID from db_Wy "&dbWhere1&")"
else
if V(62)<>"0" or V(63)<>"0" or V(64)<>"0" or V(65)<>"0" or V(66)<>"0" or V(67)<>"0" or V(68)<>"0" or V(69)<>"0" or V(70)<>"0" or V(71)<>"0" or V(72)<>"0" or V(73)<>"0" or V(74)<>"0" or V(75)<>"0" then
dbWhere1="where 1=1"
if V(62)<>"0" then dbWhere1=dbWhere1 & " and w1='" & V(62) & "'"
if V(63)="有" then
dbWhere1=dbWhere1 & " and w2<>''"
elseif V(63)="无" then
dbWhere1=dbWhere1 & " and w2=''"
end if
if V(64)<>"0" then dbWhere1=dbWhere1 & " and w3='" & V(64) & "'"
if V(65)="有" then
dbWhere1=dbWhere1 & " and w4<>''"
elseif V(65)="无" then
dbWhere1=dbWhere1 & " and w4=''"
end if
if V(66)="有" then
dbWhere1=dbWhere1 & " and w5<>''"
elseif V(66)="无" then
dbWhere1=dbWhere1 & " and w5=''"
end if
if V(67)="有" then
dbWhere1=dbWhere1 & " and w6<>''"
elseif V(67)="无" then
dbWhere1=dbWhere1 & " and w6=''"
end if

if V(68)<>"0" then dbWhere1=dbWhere1 & " and w8='" & V(68) & "'"
if V(69)="有" then
dbWhere1=dbWhere1 & " and w9<>''"
elseif V(69)="无" then
dbWhere1=dbWhere1 & " and w9=''"
end if
if V(70)<>"0" then dbWhere1=dbWhere1 & " and w11='" & V(70) & "'"
if V(71)="有" then
dbWhere1=dbWhere1 & " and w12<>''"
elseif V(71)="无" then
dbWhere1=dbWhere1 & " and w12=''"
end if
if V(72)<>"0" then dbWhere1=dbWhere1 & " and w14='" & V(72) & "'"
if V(73)="有" then
dbWhere1=dbWhere1 & " and w15<>''"
elseif V(73)="无" then
dbWhere1=dbWhere1 & " and w15=''"
end if
if V(74)<>"0" then dbWhere1=dbWhere1 & " and w16='" & V(74) & "'"
if V(75)="有" then
dbWhere1=dbWhere1 & " and w17<>''"
elseif V(75)="无" then
dbWhere1=dbWhere1 & " and w17=''"
end if
dbWhere=dbWhere & " and uID in (select uID from db_Wy "&dbWhere1&")"
end if
end if

if dbWhere<>"where 1=1" then
uID1=","
set rs=dbConn.Execute("Select uID FROM db_User "&dbWhere)
if not rs.eof then
do while not rs.eof
uID1=uID1&rs("uID")&","
rs.movenext
loop
search="YES"

if Len(uID)>Len(uID1) then
idArr=split(uID1,",")
for i = 0 to ubound(idArr)
id=idArr(i)
if id<>"" and not IsNull(id) then
if instr(uID,","&id&",")>0 then uIDArr=uIDArr&id&","
end if
next

else
idArr=split(uID,",")
for i = 0 to ubound(idArr)
id=idArr(i)
if id<>"" and not IsNull(id) then
if instr(uID1,","&id&",")>0 then uIDArr=uIDArr&id&","
end if
next
end if
if uIDArr="" then search="NO"
else
search="NO"
end if
rs.close
set rs=nothing
else
uIDArr=uID
end if
end if

uID=uIDArr
uIDArr=""
dbWhere="where 1=1"
if C(1)="1" then
dbWhere=dbWhere & " and uID in (select Distinct uID from db_Szdc where sType='A')"
end if
if C(2)="1" then
dbWhere=dbWhere & " and uID in (select Distinct uID from db_Szdc where sType='B')"
end if
if C(3)="1" then
dbWhere=dbWhere & " and uID in (select Distinct uID from db_Szdc where sType='C')"
end if
if C(4)="1" then
dbWhere=dbWhere & " and uID in (select Distinct uID from db_Lw)"
end if
if C(5)="1" then
dbWhere=dbWhere & " and uID in (select Distinct uID from db_Gw)"
end if
if C(6)="1" then
dbWhere=dbWhere & " and uID in (select Distinct uID from db_Zz)"
end if
if C(7)="1" then
dbWhere=dbWhere & " and uID in (select Distinct uID from db_Gl)"
end if
if C(8)="1" then
dbWhere=dbWhere & " and uID in (select Distinct uID from db_Gr)"
end if


if dbWhere<>"where 1=1" then
uID1=","
set rs=dbConn.Execute("Select uID FROM db_User "&dbWhere)
if not rs.eof then
do while not rs.eof
uID1=uID1&rs("uID")&","
rs.movenext
loop
search="YES"

if Len(uID)>Len(uID1) then
idArr=split(uID1,",")
for i = 0 to ubound(idArr)
id=idArr(i)
if id<>"" and not IsNull(id) then
if instr(uID,","&id&",")>0 then uIDArr=uIDArr&id&","
end if
next

else
idArr=split(uID,",")
for i = 0 to ubound(idArr)
id=idArr(i)
if id<>"" and not IsNull(id) then
if instr(uID1,","&id&",")>0 then uIDArr=uIDArr&id&","
end if
next
end if
if uIDArr="" then search="NO"
else
search="NO"
end if
rs.close
set rs=nothing
else
uIDArr=uID
end if



uIDArr=trim(replace(uIDArr,","," "))
if search="YES" and uIDArr<>"" then

uIDArr=replace(uIDArr," ",",")
sql = "Select uID,u1,u2,u3,u4,u5,uDate FROM db_User where uID in ("&uIDArr&") order by uID desc"
never1234 2003-12-16
  • 打赏
  • 举报
回复
还没完,接上:

if search="YES" then
uID=uIDArr
uIDArr=""
dbWhere="where 1=1"
if M(1)="1" then
dbWhere1="where pType='A'"
dbWhere1=dbWhere1 & " and (p1<>'' or p2<>'')"
dbWhere=dbWhere & " and uID in (select uID from db_Px "&dbWhere1&")"
else
if V(39)<>"0" or V(40)<>"0" then
dbWhere1="where pType='A'"
if V(39)<>"0" then dbWhere1=dbWhere1 & " and p1='" & V(39) & "'"
if V(40)<>"0" then
if V(40)="有" then
dbWhere1=dbWhere1 & " and p2<>''"
else
dbWhere1=dbWhere1 & " and p2=''"
end if
end if
dbWhere=dbWhere & " and uID in (select uID from db_Px "&dbWhere1&")"
end if
end if
if M(2)="1" then
dbWhere1="where pType='B'"
dbWhere1=dbWhere1 & " and (p1<>'' or p2<>'')"
dbWhere=dbWhere & " and uID in (select uID from db_Px "&dbWhere1&")"
else
if V(41)<>"0" or V(42)<>"0" then
dbWhere1="where pType='B'"
if V(41)<>"0" then dbWhere1=dbWhere1 & " and p1='" & V(41) & "'"
if V(42)<>"0" then
if V(42)="有" then
dbWhere1=dbWhere1 & " and p2<>''"
else
dbWhere1=dbWhere1 & " and p2=''"
end if
end if
dbWhere=dbWhere & " and uID in (select uID from db_Px "&dbWhere1&")"
end if
end if

if M(3)="1" then
dbWhere1="where pType='C'"
dbWhere1=dbWhere1 & " and (p1<>'' or p2<>'')"
dbWhere=dbWhere & " and uID in (select uID from db_Px "&dbWhere1&")"
else
if V(43)<>"0" or V(44)<>"0" then
dbWhere1="where pType='C'"
if V(43)<>"0" then dbWhere1=dbWhere1 & " and p1='" & V(43) & "'"
if V(44)<>"0" then
if V(44)="有" then
dbWhere1=dbWhere1 & " and p2<>''"
else
dbWhere1=dbWhere1 & " and p2=''"
end if
end if
dbWhere=dbWhere & " and uID in (select uID from db_Px "&dbWhere1&")"
end if
end if
if M(4)="1" then
dbWhere1="where pType='D'"
dbWhere1=dbWhere1 & " and (p1<>'' or p2<>'')"
dbWhere=dbWhere & " and uID in (select uID from db_Px "&dbWhere1&")"
else
if V(45)<>"0" or V(46)<>"0" then
dbWhere1="where pType='D'"
if V(45)<>"0" then dbWhere1=dbWhere1 & " and p1='" & V(45) & "'"
if V(46)<>"0" then
if V(46)="有" then
dbWhere1=dbWhere1 & " and p2<>''"
else
dbWhere1=dbWhere1 & " and p2=''"
end if
end if
dbWhere=dbWhere & " and uID in (select uID from db_Px "&dbWhere1&")"
end if
end if

if M(5)="1" then
dbWhere1="where pType='E'"
dbWhere1=dbWhere1 & " and (p1<>'' or p2<>'')"
dbWhere=dbWhere & " and uID in (select uID from db_Px "&dbWhere1&")"
else
if V(47)<>"0" or V(48)<>"0" then
dbWhere1="where pType='E'"
if V(47)<>"0" then dbWhere1=dbWhere1 & " and p1='" & V(47) & "'"
if V(48)<>"0" then
if V(48)="有" then
dbWhere1=dbWhere1 & " and p2<>''"
else
dbWhere1=dbWhere1 & " and p2=''"
end if
end if
dbWhere=dbWhere & " and uID in (select uID from db_Px "&dbWhere1&")"
end if
end if

if M(6)="1" then
dbWhere1="where pType='F'"
dbWhere1=dbWhere1 & " and (p1<>'' or p2<>'')"
dbWhere=dbWhere & " and uID in (select uID from db_Px "&dbWhere1&")"
else
if V(49)<>"0" or V(50)<>"0" then
dbWhere1="where pType='F'"
if V(49)<>"0" then dbWhere1=dbWhere1 & " and p1='" & V(49) & "'"
if V(50)<>"0" then
if V(50)="有" then
dbWhere1=dbWhere1 & " and p2<>''"
else
dbWhere1=dbWhere1 & " and p2=''"
end if
end if
dbWhere=dbWhere & " and uID in (select uID from db_Px "&dbWhere1&")"
end if
end if

if M(7)="1" then
dbWhere1="where pType='G'"
dbWhere1=dbWhere1 & " and (p1<>'' or p2<>'')"
dbWhere=dbWhere & " and uID in (select uID from db_Px "&dbWhere1&")"
else
if V(51)<>"0" or V(52)<>"0" then
dbWhere1="where pType='G'"
if V(51)<>"0" then dbWhere1=dbWhere1 & " and p1='" & V(51) & "'"
if V(52)<>"0" then
if V(52)="有" then
dbWhere1=dbWhere1 & " and p2<>''"
else
dbWhere1=dbWhere1 & " and p2=''"
end if
end if
dbWhere=dbWhere & " and uID in (select uID from db_Px "&dbWhere1&")"
end if
end if
if M(8)="1" then
dbWhere1="where pType='H'"
dbWhere1=dbWhere1 & " and (p1<>'' or p2<>'')"
dbWhere=dbWhere & " and uID in (select uID from db_Px "&dbWhere1&")"
else
if V(53)<>"0" or V(54)<>"0" then
dbWhere1="where pType='H'"
if V(53)<>"0" then dbWhere1=dbWhere1 & " and p1='" & V(53) & "'"
if V(54)<>"0" then
if V(54)="有" then
dbWhere1=dbWhere1 & " and p2<>''"
else
dbWhere1=dbWhere1 & " and p2=''"
end if
end if
dbWhere=dbWhere & " and uID in (select uID from db_Px "&dbWhere1&")"
end if
end if

if dbWhere<>"where 1=1" then
uID1=","
set rs=dbConn.Execute("Select uID FROM db_User "&dbWhere)
if not rs.eof then
do while not rs.eof
uID1=uID1&rs("uID")&","
rs.movenext
loop
search="YES"

if Len(uID)>Len(uID1) then
idArr=split(uID1,",")
for i = 0 to ubound(idArr)
id=idArr(i)
if id<>"" and not IsNull(id) then
if instr(uID,","&id&",")>0 then uIDArr=uIDArr&id&","
end if
next

else
idArr=split(uID,",")
for i = 0 to ubound(idArr)
id=idArr(i)
if id<>"" and not IsNull(id) then
if instr(uID1,","&id&",")>0 then uIDArr=uIDArr&id&","
end if
next
end if
if uIDArr="" then search="NO"
else
search="NO"
end if
rs.close
set rs=nothing
else
uIDArr=uID
end if

end if

QCN123 2003-12-16
  • 打赏
  • 举报
回复
k
never1234 2003-12-16
  • 打赏
  • 举报
回复

if search="YES" then
uID=uIDArr
uIDArr=""
dbWhere="where 1=1"

if C(1)<>"1" then

if V(22)<>"0" or V(23)<>"0" then
dbWhere1="where sType='A'"
if V(22)<>"0" then dbWhere1=dbWhere1 & " and s2='" & V(22) & "'"
if V(23)<>"0" then dbWhere1=dbWhere1 & " and s3='" & V(23) & "'"
dbWhere=dbWhere & " and uID in (select uID from db_Szdc "&dbWhere1&")"
end if
end if

if C(2)<>"1" then
if V(24)<>"0" or V(25)<>"0" then
dbWhere1="where sType='B'"
if V(24)<>"0" then dbWhere1=dbWhere1 & " and s2='" & V(24) & "'"
if V(25)<>"0" then dbWhere1=dbWhere1 & " and s3='" & V(25) & "'"
dbWhere=dbWhere & " and uID in (select uID from db_Szdc "&dbWhere1&")"
end if
end if

if C(3)<>"1" then

if V(26)<>"0" or V(27)<>"0" then
dbWhere1="where sType='C'"
if V(26)<>"0" then dbWhere1=dbWhere1 & " and s2='" & V(26) & "'"
if V(27)<>"0" then dbWhere1=dbWhere1 & " and s3='" & V(27) & "'"
dbWhere=dbWhere & " and uID in (select uID from db_Szdc "&dbWhere1&")"
end if
end if

if dbWhere<>"where 1=1" then
uID1=","
set rs=dbConn.Execute("Select uID FROM db_User "&dbWhere)
if not rs.eof then
do while not rs.eof
uID1=uID1&rs("uID")&","
rs.movenext
loop
search="YES"

if Len(uID)>Len(uID1) then
idArr=split(uID1,",")
for i = 0 to ubound(idArr)
id=idArr(i)
if id<>"" and not IsNull(id) then
if instr(uID,","&id&",")>0 then uIDArr=uIDArr&id&","
end if
next

else
idArr=split(uID,",")
for i = 0 to ubound(idArr)
id=idArr(i)
if id<>"" and not IsNull(id) then
if instr(uID1,","&id&",")>0 then uIDArr=uIDArr&id&","
end if
next
end if
if uIDArr="" then search="NO"
else
search="NO"
end if
rs.close
set rs=nothing
else
uIDArr=uID
end if

end if





if search="YES" then
uID=uIDArr
uIDArr=""
dbWhere="where 1=1"

if C(4)<>"1" then
if V(28)<>"0" or V(29)<>"0" or V(30)<>"0" then
dbWhere1="where 1=1"
if V(28)<>"0" then dbWhere1=dbWhere1 & " and l3='" & V(28) & "'"
if V(29)<>"0" then dbWhere1=dbWhere1 & " and l4='" & V(29) & "'"
if V(30)<>"0" then dbWhere1=dbWhere1 & " and l6='" & V(30) & "'"
dbWhere=dbWhere & " and uID in (select uID from db_Lw "&dbWhere1&")"
end if
end if

if C(5)<>"1" then

if V(31)<>"0" or V(32)<>"0" or V(33)<>"0" then
dbWhere1="where 1=1"
if V(31)<>"0" then dbWhere1=dbWhere1 & " and g3='" & V(31) & "'"
if V(32)<>"0" then dbWhere1=dbWhere1 & " and g4='" & V(32) & "'"
if V(33)<>"0" then dbWhere1=dbWhere1 & " and g5='" & V(33) & "'"
dbWhere=dbWhere & " and uID in (select uID from db_Gw "&dbWhere1&")"
end if
end if

if C(6)<>"1" then
if V(34)<>"0" then dbWhere=dbWhere & " and uID in (select uID from db_Zz where z3='"&V(34)&"')"
end if

if C(7)<>"1" then
if V(35)<>"0" or V(36)<>"0" then
dbWhere1="where 1=1"
if V(35)<>"0" then dbWhere1=dbWhere1 & " and g2='" & V(35) & "'"
if V(36)<>"0" then dbWhere1=dbWhere1 & " and g3='" & V(36) & "'"
dbWhere=dbWhere & " and uID in (select uID from db_Gl "&dbWhere1&")"
end if
end if

if C(8)<>"1" then
if V(37)<>"0" or V(38)<>"0" then
dbWhere1="where 1=1"
if V(37)<>"0" then dbWhere1=dbWhere1 & " and g1='" & V(37) & "'"
if V(38)<>"0" then dbWhere1=dbWhere1 & " and g2='" & V(38) & "'"
dbWhere=dbWhere & " and uID in (select uID from db_Gr "&dbWhere1&")"
end if
end if

if dbWhere<>"where 1=1" then
uID1=","
set rs=dbConn.Execute("Select uID FROM db_User "&dbWhere)
if not rs.eof then
do while not rs.eof
uID1=uID1&rs("uID")&","
rs.movenext
loop
search="YES"

if Len(uID)>Len(uID1) then
idArr=split(uID1,",")
for i = 0 to ubound(idArr)
id=idArr(i)
if id<>"" and not IsNull(id) then
if instr(uID,","&id&",")>0 then uIDArr=uIDArr&id&","
end if
next

else
idArr=split(uID,",")
for i = 0 to ubound(idArr)
id=idArr(i)
if id<>"" and not IsNull(id) then
if instr(uID1,","&id&",")>0 then uIDArr=uIDArr&id&","
end if
next
end if
if uIDArr="" then search="NO"
else
search="NO"
end if
rs.close
set rs=nothing
else
uIDArr=uID
end if

end if

never1234 2003-12-16
  • 打赏
  • 举报
回复
最后写成了这样:
看看这一大堆东西,混在一起查500%都会死。
(注:不要说不注重命名)


uIDArr=""
dbWhere="where 1=1"
Dim V(75)
Dim C(8)
Dim M(10)
for i=1 to 75
V(i)=ChkRequest(request.form("v"&i))
next
for i=1 to 8
C(i)=cstr(ChkRequest(request.form("C"&i)))
next
for i=1 to 10
M(i)=cstr(ChkRequest(request.form("M"&i)))
next
Danwei=ChkRequest(request.form("danwei"))
zy=ChkRequest(request.form("zy"))
sx1=ChkRequest(request.form("sx1"))
sx2=ChkRequest(request.form("sx2"))
sx3=ChkRequest(request.form("sx3"))
sx4=ChkRequest(request.form("sx4"))
sx5=ChkRequest(request.form("sx5"))
AO=ChkRequest(request.form("AO"))

'用户

if Danwei<>"" then dbWhere=dbWhere & " and u5 like '%" & Danwei & "%'"
if zy<>"0" then
select case (zy)
case "其他"
dbWhere=dbWhere & " and u13 not like '%文科%' and u13 not like '%理科%' and u13 not like '%管理%' and u13 not like '%党建%'"
case else
dbWhere=dbWhere & " and u13 like '%"&zy&"%'"
end select
end if
if V(1)<>"0" then dbWhere=dbWhere & " and u2='" & V(1) & "'"
if V(3)<>"0" then dbWhere=dbWhere & " and u4='" & V(3) & "'"
if V(2)<>"0" then
if V(2)="无职务" then
if AO="非" then
dbWhere=dbWhere & " and u3<>''"
else
dbWhere=dbWhere & " and u3=''"
end if
else
if AO="非" then
dbWhere=dbWhere & " and u3<>'" & V(2) & "'"
else
dbWhere=dbWhere & " and u3='" & V(2) & "'"
end if
end if
end if

if V(4)<>"0" then dbWhere=dbWhere & " and u6='" & V(4) & "'"

if V(5)<>"0" then
select case V(5)
case 1
date1=1
date2=36
case 2
date1=35
date2=46
case 3
date1=45
date2=55
case 4
date1=54
date2=100
end select
dbWhere=dbWhere & " and datediff('yyyy',u7,'"&date&"')>"&date1&" and datediff('yyyy',u7,'"&date&"')<"&date2&""
end if
if V(6)<>"0" then
select case V(6)
case 1
date1=-1
date2=6
case 2
date1=5
date2=21
case 3
date1=20
date2=31
case 4
date1=30
date2=100
end select
dbWhere=dbWhere & " and datediff('yyyy',u8,'"&date&"')>"&date1&" and datediff('yyyy',u8,'"&date&"')<"&date2&""
end if

if V(7)<>"0" then
select case V(7)
case 1
date1=-1
date2=6
case 2
date1=5
date2=16
case 3
date1=15
date2=31
case 4
date1=30
date2=100
end select
dbWhere=dbWhere & " and datediff('yyyy',u9,'"&date&"')>"&date1&" and datediff('yyyy',u9,'"&date&"')<"&date2&""
end if


if V(8)<>"0" then dbWhere=dbWhere & " and u10='" & V(8) & "'"
if V(9)<>"0" then dbWhere=dbWhere & " and u11='" & V(9) & "'"
if V(10)<>"0" then dbWhere=dbWhere & " and u12='" & V(10) & "'"
if V(11)<>"0" then dbWhere=dbWhere & " and u15='" & V(11) & "'"
Call OpenDB()

uID=","
search="NO"

set rs=dbConn.Execute("Select uID FROM db_User "&dbWhere)
if not rs.eof then
do while not rs.eof
uID=uID&rs("uID")&","
rs.movenext
loop

search="YES"
uIDArr=uID
end if
rs.close
set rs=nothing

if search="YES" then
dbWhere="where 1=1"
uIDArr=""
if V(12)<>"0" or V(13)<>"0" or sx1<>"0" then
dbWhere1="where zType='A'"
if V(12)="A" then
dbWhere1=dbWhere1 & " and z2<>''"
else
if V(12)<>"0" then dbWhere1=dbWhere1 & " and z2='" & V(12) & "'"
end if
if V(13)<>"0" then dbWhere1=dbWhere1 & " and z3='" & V(13) & "'"
if sx1<>"0" then
if sx1="1" then
dbWhere1=dbWhere1 & " and z1 like '%党校%'"
else
dbWhere1=dbWhere1 & " and z1 not like '%党校%'"
end if
end if
dbWhere=dbWhere & " and uID in (select uID from db_Zsdc "&dbWhere1&")"
end if

if V(14)<>"0" or V(15)<>"0" or sx2<>"0" then
dbWhere1="where zType='B'"
if V(14)="A" then
dbWhere1=dbWhere1 & " and z2<>''"
else
if V(14)<>"0" then dbWhere1=dbWhere1 & " and z2='" & V(14) & "'"
end if
if V(15)<>"0" then dbWhere1=dbWhere1 & " and z3='" & V(15) & "'"
if sx2<>"0" then
if sx2="1" then
dbWhere1=dbWhere1 & " and z1 like '%党校%'"
else
dbWhere1=dbWhere1 & " and z1 not like '%党校%'"
end if
end if
dbWhere=dbWhere & " and uID in (select uID from db_Zsdc "&dbWhere1&")"
end if

if V(16)<>"0" or V(17)<>"0" or sx3<>"0" then
dbWhere1="where zType='C'"
if V(16)="A" then
dbWhere1=dbWhere1 & " and z2<>''"
else
if V(16)<>"0" then dbWhere1=dbWhere1 & " and z2='" & V(16) & "'"
end if
if V(17)<>"0" then dbWhere1=dbWhere1 & " and z3='" & V(17) & "'"
if sx3<>"0" then
if sx3="1" then
dbWhere1=dbWhere1 & " and z1 like '%党校%'"
else
dbWhere1=dbWhere1 & " and z1 not like '%党校%'"
end if
end if
dbWhere=dbWhere & " and uID in (select uID from db_Zsdc "&dbWhere1&")"
end if

if V(18)<>"0" or V(19)<>"0" or sx4<>"0" then
dbWhere1="where zType='D'"
if V(18)="A" then
dbWhere1=dbWhere1 & " and z2<>''"
else
if V(18)<>"0" then dbWhere1=dbWhere1 & " and z2='" & V(18) & "'"
end if
if V(19)<>"0" then dbWhere1=dbWhere1 & " and z3='" & V(19) & "'"
if sx4<>"0" then
if sx4="1" then
dbWhere1=dbWhere1 & " and z1 like '%党校%'"
else
dbWhere1=dbWhere1 & " and z1 not like '%党校%'"
end if
end if
dbWhere=dbWhere & " and uID in (select uID from db_Zsdc "&dbWhere1&")"
end if

if V(20)<>"0" or V(21)<>"0" or sx5<>"0" then
dbWhere1="where zType='E'"
if V(20)="A" then
dbWhere1=dbWhere1 & " and z2<>''"
else
if V(20)<>"0" then dbWhere1=dbWhere1 & " and z2='" & V(20) & "'"
end if
if V(21)<>"0" then dbWhere1=dbWhere1 & " and z3='" & V(21) & "'"
if sx5<>"0" then
if sx5="1" then
dbWhere1=dbWhere1 & " and z1 like '%党校%'"
else
dbWhere1=dbWhere1 & " and z1 not like '%党校%'"
end if
end if
dbWhere=dbWhere & " and uID in (select uID from db_Zsdc "&dbWhere1&")"
end if

if dbWhere<>"where 1=1" then
uID1=","
set rs=dbConn.Execute("Select uID FROM db_User "&dbWhere)
if not rs.eof then
do while not rs.eof
uID1=uID1&rs("uID")&","
rs.movenext
loop
search="YES"

if Len(uID)>Len(uID1) then
idArr=split(uID1,",")
for i = 0 to ubound(idArr)
id=idArr(i)
if id<>"" and not IsNull(id) then
if instr(uID,","&id&",")>0 then uIDArr=uIDArr&id&","
end if
next

else
idArr=split(uID,",")
for i = 0 to ubound(idArr)
id=idArr(i)
if id<>"" and not IsNull(id) then
if instr(uID1,","&id&",")>0 then uIDArr=uIDArr&id&","
end if
next
end if
if uIDArr="" then search="NO"
else
search="NO"
end if
rs.close
set rs=nothing
else
uIDArr=uID
end if
end if
never1234 2003-12-16
  • 打赏
  • 举报
回复
沉了这么久的帖子居然又上来了?哈哈,搞笑。

61(儿童节快乐), centurybobo(大笨鸟) 写的最后结果是不一样的,前者的好象可以,后者的结果不一样,不是or而是and,同时满足。

不过,这么多条件不管怎么写,如果用一条SQL查询在本机运行都会死机,但实际上,真正查询时这些条件只是一部分,这是一个某政府机关里的某人提出来的,完整的查询条件一共有97个,混在一起根本没办法查,后来用的是分开几部分写,设置一个变量,反正全都是and条件(不过后来又要求加了十多个or条件),如果前一部分查无记录,把变量变为false,就不用再查后面的了。

顺便说一句,这是查得出记录的,认为查不出的再仔细看看,hoho……

差点把我整死。
超级大笨狼 2003-12-15
  • 打赏
  • 举报
回复
哈哈,搞笑!
liuqinglq 2003-12-15
  • 打赏
  • 举报
回复
帖主发这个帖子不是来求答案的?
jfly301 2003-12-15
  • 打赏
  • 举报
回复
sql语句真是有很多地方值得研究啊,
要简化
wangsf 2003-12-15
  • 打赏
  • 举报
回复
我顶上的说的很对了我就没有必要重复了
yonghengdizhen 2003-12-15
  • 打赏
  • 举报
回复
楼主该学学如何化简逻辑表达式了
yonghengdizhen 2003-12-15
  • 打赏
  • 举报
回复
直接
Select uID,u1,u2,u3,u4,uDate FROM db_User where 1=1 and 1=0 一了百了
xzq686 2003-12-15
  • 打赏
  • 举报
回复
楼主的语句是够BT够NB的!
我看到都耳鸣了!
加载更多回复(20)

28,404

社区成员

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

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