如题所述
declare @select nvarchar(200)='select ...where ... like ''%'
select @select=@select+@tmp+'%'''
exec (@select)追问
dim shumin
shumin="不"
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.open "C:\Inetpub\wwwroot\myweb\db1.mdb"
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "SELECT shuming as [书名],zuozhe as [作者 FROM biao1 where shuming like %shumin%", conn %>
这样能查出结果吗?我试过了,怎么页面不能运行哦?
首先你最后拼成的一个完整的sql应该是什么样子呢
SELECT shuming as [书名],zuozhe as [作者] FROM biao1 where shuming like '%不%'
首先注意一点:like后面的条件 是放在单引号里的 '' 例如 '%不%'
那么你上面的话至少应该是这个样子的
rs.Open "SELECT shuming as [书名],zuozhe as [作者] FROM biao1 where shuming like ‘%"+shumin+"%’", conn %>
修改为:
rs.Open "SELECT shuming as [书名],zuozhe as [作者 FROM biao1 where shuming like %" + shumin + "%", conn %>追问
怎么还是不行哦,朋友?
朋友,你这里的"%value1%"只是常量,我的意思是用一个变量来表示条件,行不行?
dim shumin
shumin="不"
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.open "C:\Inetpub\wwwroot\myweb\db1.mdb"
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "SELECT shuming as [书名],zuozhe as [作者 FROM biao1 where shuming like %shumin%", conn %>
这样能查出结果吗?我试过了,怎么页面不能运行哦?
rs.Open "SELECT shuming as [书名],zuozhe as [作者 FROM biao1 where shuming like %shumin%", conn %>
关键这句。。。