
- #Sql server find unprintable characters how to
- #Sql server find unprintable characters update
- #Sql server find unprintable characters full
- #Sql server find unprintable characters code
The LEN() function gives you the number of characters in a character string but it trims the trailing empty spaces. Using LEN()/DATALENGTH() to find leading and trailing spaces Let’s investigate a couple of methods in which to find out what is happening in these strings. I will discuss this in a bit more detail later. For example: are stings case insensitive or not (is "ZombieLand" = "zombieland"?) or are a string’s accent sensitive or not (is Ça = Ca).
#Sql server find unprintable characters how to
Collation is SQL Server’s way of knowing how to sort and compare data. There is however some basic things you should know. If you need further information here is a good place to start.
#Sql server find unprintable characters full
CollationĪ full examination of collation is out of the scope of this article. This means the column is case and accent sensitive. One last thing, the collation of the THE_TEXT is Latin1_General_CS_AS. This particular error/issue will come up later. It has multiple spaces between “Zombie” and “Land”. I created character expressions with spaces at the beginning and end as well as added special characters (“/”,”#”) in the middle. ('ACCENTS','Régie du logement - Gouvernement du Québec'),Īlso, look at a number of the problems. ('SPECIAL CHARACTERS MULTIPLE SPACES','35 Zombie Land Apt 13'), ('SPECIAL CHARACTERS \','This and\or that'), ('SPECIAL CHARACTERS /','This and/or that'), ('SPECIAL CHARACTERS - # SYMBOL','35 Zombie Land Apt. ('SPECIAL CHARACTERS - APOSTROPHE','Zombie''s Land'), ('SPECIAL CHARACTERS - CARRAGE RETURN LINE FEED','Zombieland' + CHAR(13) + CHAR(10)), ('SPACE AT START AND END', N' Zombieland '), ,THE_TEXT NVARCHAR(60) COLLATE Latin1_General_CS_AS IF (SELECT OBJECT_id(N'TEST_DATA','U')) IS NOT NULL So the “EXAMPLE_TYPE” can be “SPACE AT END” and “THE_TEXT” has a piece of text with a space at the end (‘Zombieland ‘). The first column is a description of the key component we are looking at in the 2 nd column. The script below will create a table with 2 columns. What I do is run them against the data every morning and send out emails to those responsible so they can correct them before the issue starts to manifest. Over the years I have compiled a small library of queries that I hope you will find as useful as I have. The reality is that even if you have a great deal of control over the data, this stuff always sneaks in. These issues manifest as odd characters on a report, off center titles, screens not opening, orders failing to get created and the list goes on. In addition many times the errors associated with the problem have nothing to do with identifying the character, but are related to the issue it is causing. When working with multiple source systems wouldn't it be nice if everyone could agree on what characters were acceptable.
#Sql server find unprintable characters code
The code can be used for finding those annoying hidden non-alpha numeric characters or if you are just interested to see what type of characters exist in your data.Special characters are one of those necessary evils. So now I have a quick way to go through and figure out what characters exist in any column on my table. Previously I was cleansing data with Char 32, which is a space and cannot really be seen by just glancing at the data. SET ColumnName= REPLACE(Columnname, CHAR(13),'')
#Sql server find unprintable characters update
So I ran the following update to fix the problem: In my case, I had a problem with character #13, which is a carriage return that was added to each row of data in my flat file and somehow made it to my staging table during import. It will display the ASCII character code number and the first position of that character in your column. In the code below, just insert your own table name (with schema if you want) and column name.Īfter running the code, you will see in the results table which character yielded results and you can go ahead and update your data accordingly. So I had to write some dynamic t-sql to help me out. I didn’t have time to test all 255 characters to see what was in my numeric field. The link below has the ASCII Character set: But which character in my data is non-numeric? Well you could use the CHARINDEX function to figure out where a certain character set exists in your data but you would have to know which code to use. One of the best ways to find out if your data has some non-numeric characters in it is by running a simple query. However, my data was numeric I checked it many times… or was it really 100% numeric?Īpparently there are some crazy hidden characters that you cannot see when you just glimpse at data. The problem was a conversion problem from varchar type to float and I kept getting the following error:Įrror converting data type varchar to float. It was supposed to be a standard run for our quarterly data aggregations but one of the data import SSIS packages kept failing.
