Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to identify non ascii characters in database column

Status
Not open for further replies.

jasonhuibers

Programmer
Sep 12, 2005
290
CA
In my table Table1 , there is a column in which we need to identify all non ascii character? We can run the query and provide the list of records in which there is a non ascii character and the data can be cleaned up the by customer. How can I do this in a query?
 
I'd use the ASCII function in conjunction with SUBSTRING and check every row. Numbers table joined on LEN(column_to_check) to step through each character.

soi là, soi carré
 
I suspect that you need to better qualify what you consider to be an ASCII character. By definition, anything in a varchar column is ASCII. I suspect you want to actually check for certain characters that are not within a certain set of acceptable characters. For example, a list of acceptable characters might be ({space},.-$a (through) z, (0-9), etc....).

I would encourage you to take a look at this query. It probably won't be exactly what you are looking for, but it may be a good place to start.

Code:
Select ColumnName 
From   TableName 
Where  ColumnName like '%[^a-z ,-.'0-9]%'



-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
What is the data type of the column? I suspect you may try playing with this idea

select * from myColumn where mynvarcharColumn <> convert(varchar(max), myNvarcharColumn) -- this should find all records with non-ASCII chars.

PluralSight Learning Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top