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

asp查询中包含方括号,查询


有个字段的字符串   里面包含[]比如值可能是:
20060801[CSDN]我们是最好的程序员网站

title= " '% " " "&title& " " "% ' "
sql= "select   *   from   book   where   title   LIKE   "&ydf_title

但是查询不到数据。还请帮忙指点一下

------解决方案--------------------
replace(replace(ss, "[ ", "[[] "), "] ", "[]] ")
------解决方案--------------------
title = Replace(title, "[ ", "[[] ")
ydf_title= " '% "&title& "% ' "
sql= "select * from book where title LIKE "&ydf_title
------解决方案--------------------
来晚了,[]是SQL的保留符,必需替换,就像 '要换成 ' '一样
------解决方案--------------------
在单引号中,没有保留符,楼主可以不管他
------解决方案--------------------
支持楼上
ydf_title = " '% " & title & "% ' "
sql= "select * from book where title LIKE " & ydf_title
------解决方案--------------------
title= " '% " " "&title& " " "% ' "
sql= "select * from book where title LIKE "&ydf_title

应该是
sql= "select * from book where title LIKE "&title
只看到title定义成 "%xx% "样式,没看到ydf_title,楼主应该是写错了吧
还有[]在单引号内确实不需要替换
------解决方案--------------------
ESCAPE 关键字定义转义符
sql= "select * from book where (title LIKE '% "[% "]% ' ESCAPE ' " ')
------解决方案--------------------
同意楼上,ESCAPE
------解决方案--------------------
sql = "select * from book where title LIKE '% " & Replace(sTitle, "[ ", "[[] ") & "% ' "