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)

因為我發現他們兩個轉完之后,不一樣啊!如下圖,所以才轉成字符串的

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM