日期:2014-05-17  浏览次数:21158 次

把access转成SQL后,出现的关于instr()的问题?
<select   name= "late_name "   id= "select ">
      <%
            user_late=split(request.Cookies( "username ")( "late "), ", ")
    user_id=request.Cookies( "username ")( "id ")
    Art_class=request( "Art_class ")
    for   i=0   to   ubound(user_late)
          if   Art_class=trim(user_late(i))   then
  response.Write( " <option   selected> "&user_late(i)& " </option> ")
  else
  response.Write( " <option> "&user_late(i)& " </option> ")
  end   if
  set   rs=server.CreateObject( "adodb.recordset ")
  sql   =   "select   栏目子类   from   late   where   栏目大类= ' "&trim(user_late(i))& " '   and   instr(管理人员, ' "&user_id& " ') <> 0 "                                                         ----------这段出问题
  rs.open   sql,conn,1,1
  do   while   not   rs.eof
          if   Art_class=trim(user_late(i))   then
                  response.Write( " <option   value= "&trim(user_late(i))& ", "&rs( "栏目子类 ")& "> &nbsp;&nbsp;├&nbsp; "&rs( "栏目子类 ")& " </option> ")
          else
                  response.Write( " <option   value= "&trim(user_late(i))& ", "&rs( "栏目子类 ")& "> &nbsp;&nbsp;├&nbsp; "&rs( "栏目子类 ")& " </option> ")
          end   if
  rs.movenext
  loop
  rs.close
  set   rs=nothing
    next
      %>
                </select>

======================
  sql   =   "select   栏目子类   from   late   where   栏目大类= ' "&trim(user_late(i))& " '   and   instr(管理人员, ' "&user_id& " ') <> 0 "                                                 ----------这段出问题


------解决方案--------------------
sql = "select 栏目子类 from late where 栏目大类= ' "&trim(user_late(i))& " ' and CHARINDEX( ' "&user_id& " ',管理人员) "
------解决方案--------------------
instr是VB中的函数,在SQL中没有,你可以用charindex
------解决方案--------------------
sql = "select 栏目子类 from late where 栏目大类 like ' "&trim(user_late(i))& " ' and CHARINDEX( ' "&user_id& " ',管理人员)> 0 "


sql语句中charindex(要查找的字符串,从那个字符串中找)