sql server乱码显示问题
【1】问题
直接查询表,表中的字段是乱码,不管用UTF8、还是用 GBK,这些就是不显示,什么垃圾特殊字符写着里面
发现其这个 customerid 在sql server客户端显示是一串空白,但是在程序段显示是乱码
在ssms中,我们是可以这么关联的,你看我贴出来都有错误,但在ssms中,是一串空白
select *,cast(customerid as varbinary) from PTCustomer WITH(NOLOCK) WHERE customerid=' ' select * from customer with(nolock) where customerid = ' '
直接关联:也是可以的
select * from customer with(nolock) where customerid = (select customerid from PTCustomer WITH(NOLOCK) WHERE ptid = 'nbbf5110006')
【2】解决:特殊字符转成二进制后
干脆已二进制的方法提取出来;
然后用二进制做匹配
select *,cast(customerid as varbinary) from PTCustomer WITH(NOLOCK) WHERE ptid = 'nbbf5110006' select * from customer with(nolock) where cast(CUSTOMERID as char)=cast(0xA7F3A6FB as char)
有人要问了,为什么不直接用二进制匹配,还要 特地转成字符串?
where cast(CUSTOMERID as char)=cast(0xA7F3A6FB as char)
因为我发现他们两个转完之后,不一样啊!如下图,所以才转成字符串的