if accute=1 then      //accute表示是否模糊查询
   OP="LIKE '%" & 变量 & "%'"
else
   OP="='" & 变量 & "'"
end ifsqlstr="Select * from 表名 where 字段名 "&OP&" and left(pubdate,4) between datefrom and dateto "

解决方案 »

  1.   

    如果datefrom,dateto也是变量:if accute=1 then      //accute表示是否模糊查询
       OP="LIKE '%" & 变量 & "%'"
    else
       OP="='" & 变量 & "'"
    end ifsqlstr="Select * from 表名 where 字段名 "&OP&" and left(pubdate,4) between '" & datefrom & "' and  '" & dateto & "'"
      

  2.   

    if accute=1 then      //accute表示是否模糊查询
       OP="LIKE '"
    else
       OP="= '"
    end if
    sqlstr="Select * from 表名 where 字段名 " & OP & 变量 & "' and left(pubdate,4) between datefrom and dateto "
      

  3.   

    if accute=1 then      //accute表示是否模糊查询
       OP="LIKE '"
    else
       OP="= '"
    end if
    sqlstr="Select * from 表名 where 字段名 "&OP&" and left(pubdate,4) between '" & datefrom & "' and  '" & dateto & "'"
      

  4.   

    if accute=1 then      //accute表示是否模糊查询
       OP="LIKE '%" & 变量 & "%'"
    else
       OP="='" & 变量 & "'"
    end ifsqlstr="Select * from 表名 where 字段名 "&OP&" and left(pubdate,4) between datefrom and dateto "
      

  5.   

    if accute=1 then      //accute表示是否模糊查询
       OP="LIKE '%" & 变量 & "%'"
    else
       OP="='" & 变量 & "'"
    end ifsqlstr="Select * from 表名 where 字段名 " & OP & " and left(pubdate,4) between '" & datefrom & "' and '" & dateto "'"
      

  6.   


    if accute=1 then      //accute表示是否模糊查询
       OP="LIKE '%" & 变量 & "%'"
    else
       OP="='" & 变量 & "'"
    end ifsqlstr="Select * from 表名 where 字段名 "&OP&" and left(pubdate,4) between datefrom and dateto "应该考虑多个变量和字段名的时候