select ……where……like查询语句中,like后面怎么用变量表示条件?
4个回答
展开全部
declare @tmp nvarchar(10)='ab'
declare @select nvarchar(200)='select ...where ... like ''%'
select @select=@select+@tmp+'%'''
exec (@select)
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 %>
修改为:
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 %>
追问
怎么还是不行哦,朋友?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select * from table1 where field1 like ’%value1%’
追问
朋友,你这里的"%value1%"只是常量,我的意思是用一个变量来表示条件,行不行?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
like %aaaa%
追问
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 %>
关键这句。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询