程序如下:<!--#include file="conn.asp"-->
<%
i_id=10
        Dim rs6,sql,rs7,i,industrystr,industryarray,sqlindustry
sql = "Select industry_one_id from company order by ID desc"
Set rs6 = Conn.Execute(sql)
if rs6.eof and rs6.bof then
else
do while not rs6.eof
industrystr = rs6("industry_one_id")
response.Write industrystr
response.write "<br>"
industryarray = split(industrystr,",")
For i = 0 to UBound(industryarray)
 if ubound(industryarray)=0 then
sql2 = "select * from company where verify=0  and "&industryarray(i)&"="&i_id&"  order by count desc"
 elseif ubound(industryarray)>0 then
sqlindustry = sqlindustry & "or "&i_id&"="&industryarray(i)&" "
sql2 = "select * from company where verify=0  "&sqlindustry&"  order by count desc"
end if
Next
response.Write sql2
response.write "<br>----------!!!!!!<br>"
rs6.movenext
loop
end if
rs6.close
Set rs6 = Nothing
%>
输出结果:
14,15,16,17,18
select * from company where verify=0 or 10=14 or 10=15 or 10=16 or 10=17 or 10=18 order by count desc
----------!!!!!!
5,6
select * from company where verify=0 or 10=14 or 10=15 or 10=16 or 10=17 or 10=18 or 10=5 or 10=6 order by count desc
----------!!!!!!
8
select * from company where verify=0 and 8=10 order by count desc
----------!!!!!!
1,2,3
select * from company where verify=0 or 10=14 or 10=15 or 10=16 or 10=17 or 10=18 or 10=5 or 10=6 or 10=1 or 10=2 or 10=3 order by count desc
----------!!!!!!
11,12,13,16
select * from company where verify=0 or 10=14 or 10=15 or 10=16 or 10=17 or 10=18 or 10=5 or 10=6 or 10=1 or 10=2 or 10=3 or 10=11 or 10=12 or 10=13 or 10=16 order by count desc
----------!!!!!!
10
select * from company where verify=0 and 10=10 order by count desc
----------!!!!!!我要的结果:
14,15,16,17,18
select * from company where verify=0 or 10=14 or 10=15 or 10=16 or 10=17 or 10=18 order by count desc
----------!!!!!!
5,6
select * from company where verify=0 or 10=5 or 10=6 order by count desc
----------!!!!!!
8
select * from company where verify=0 and 8=10 order by count desc
----------!!!!!!
1,2,3
select * from company where verify=0 or 10=1 or 10=2 or 10=3 order by count desc
----------!!!!!!
11,12,13,16
select * from company where verify=0 or 10=11 or 10=12 or 10=13 or 10=16 order by count desc
----------!!!!!!
10
select * from company where verify=0 and 10=10 order by count desc
----------!!!!!!
company数据库结构:id        industry_one_id
1 10
2 11,12,13,16
3 1,2,3
4 8
5 5,6
6 14,15,16,17,18看了很久都找不到怎样修改的好方法,
大家帮忙看看怎样写
搞到头晕想不到为什么会出现:
11,12,13,16  
select  *  from  company  where  verify=0  or  10=14  or  10=15  or  10=16  or  10=17  or  10=18  or  10=5  or  10=6  or  10=1  or  10=2  or  10=3  or  10=11  or  10=12  or  10=13  or  10=16  order  by  count  desc  我要的结果是:
11,12,13,16  
select  *  from  company  where  verify=0  or  10=11  or  10=12  or  10=13  or  10=16  order  by  count  desc  谢谢了

解决方案 »

  1.   

    rs6.movenext前面加一句:sqlindustry = ""
      

  2.   

    问题解决了,顺便问问
    用SQL语句可以直接实现吗?
    怎样写?
    谢谢
      

  3.   

    11,12,13,16  
    select  *  from  company  where  verify=0  or  10=11  or  10=12  or  10=13  or  10=16  order  by  count  desc  
    ============
    11,12,13,16  
    select  *  from  company  where  verify=0  or  10 in(11,12,13,16) order  by  count  desc