Blog Post

Identifying records with special characters (Unicode)

,

Occasionally Data analyst may fall in a situation, where they need to identify records holding special characters or only the records having no special records at all. It is fairly simple to identify such records.

Let us start with creating a simple table and inserting both type of character values.

InsertNVarcharCharacter

 

Now logically, if you try to convert a NVARCHAR value to VARCHAR, SQL will fail to translate it and convert the special characters into “?”.

ConvertN_ToVarchar

We use the same logic to identify our records.

To find only the Non-Unicode Character use below query. Only the records which  are successfully converted into varchar will be able to match the original column.

SELECT *

FROM #t

Where CONVERT(varchar(20),CompanyName) = CompanyName

VarcharCharacter

 

To identify only the records with special character just replace = with <>

SELECT *

FROM #t

Where CONVERT(varchar(20),CompanyName) = CompanyName.

 

Let me know your views, questions or any other method of doing same. If you are novice and want to know more detail about VARCHAR and NVARCHAR, Drop your query in  comments i will pick that up for future.

Original post (opens in new tab)
View comments in original post (opens in new tab)

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating