name字段是char(n)类型,字符串尾部有空格或不可见字符。select * from table1 where substring(name,1,len('awedr0987er'))='awedr0987er'
awedr0987er后面有全角的空格,或者是其他不可见的字符.
如果楼上的不行的话,可以试试: select * from table1 where replace(name,' ','')='awedr0987er' 就是把中文空格去掉。 如果原来字符串中没有中文空格的话,可以这样使用。 (问题应该是出现在尾部)
--用下面的可以看到多余字符串的代码 select cast(stuff(name,1,11,'') as varbinary) from table1 where name like 'awedr0987er%'
Ltrim,rtirm只能除掉左边,右边的空格,所以Enter键不可能去掉!我这里有个有enter键的资料,如果不用like,必须是 select * from a where a_add = 'bb' + char(13)--char(13)为enter键或者 select a_add,a_nam from a where replace(a_add,char(13),'') = 'bb'才可以查询出来!
select * from table1 where replace(name,' ','')='awedr0987er'
就是把中文空格去掉。
如果原来字符串中没有中文空格的话,可以这样使用。
(问题应该是出现在尾部)
select cast(stuff(name,1,11,'') as varbinary)
from table1 where name like 'awedr0987er%'
select * from a where a_add = 'bb' + char(13)--char(13)为enter键或者
select a_add,a_nam
from a where replace(a_add,char(13),'') = 'bb'才可以查询出来!
如果你的字段为varchar(15),‘awedr0987er’存储后则为'awedr0987er'
回车这个字符可以在VB的dataGrid里边看到,是2个小方块。
我那次弄出来的原因是,我用查询分析器查询出来数据后用ctrl+C,ctrl+V 直接加到表字段里的。从查询分析器的字段信息,拷贝到SQL脚本区域,会看到光标换行了。
估計是這個問題