-1

I recently had an issue with an SSIS package where it failed to export the data in a SQL table. I was able to narrow down the problem to a record which contained a strange character in one field. The field was CUST_NAME and the value in it was:

GUY & O�NEILL, INC.

Of course, the question mark inside the diamond should have been an apostrophe.

Is there any way to track these sort of strange characters using a query? I'd want to search the whole table, but for all "out of the ordinary" characters. I have no idea where to even start.

6
  • What is an "out of the ordinary" character? Commented Jan 9, 2023 at 17:47
  • @Larnu - Basically, anything you wouldn't expect. Like that weird diamond. I don't know what other weird characters might show up, because I definitely wasn't expecting that one. Commented Jan 9, 2023 at 17:50
  • That could be anything. The above looks like a name, for example, so I wouldn't expect a number. So would LIKE '%[^A-z ]%' work? That will, of course, also flag due to the comma and the period. Commented Jan 9, 2023 at 17:51
  • @larnu - Well, I'd expect numbers, some punctuation (i.e. "O'Neill" or "Catch 21") would be within the realm of a customer name, but definitely not a square or a diamond. I'm trying to think what other symbols I've seen that aren't within the normal ASCII values. Basically, anything that might trip up an SSIS package trying to export data to a CSV file. Commented Jan 9, 2023 at 17:54
  • 2
    Such a character wouldn't "trip up" an SSIS package though. SSIS supports nvarchar data using the WSTR datatype. Commented Jan 9, 2023 at 17:56

1 Answer 1

0

I just found some code that does what I need. For anyone who might have a similar issue, I used this code:

SELECT
    CASE_NUMBER,
    ACCOUNT_FULL_NAME,
    patindex('%[^ !-~]%' COLLATE Latin1_General_BIN,ACCOUNT_FULL_NAME) as [Position],
    substring(ACCOUNT_FULL_NAME,patindex('%[^ !-~]%' COLLATE Latin1_General_BIN,ACCOUNT_FULL_NAME),1) as [InvalidCharacter],
    ascii(substring(ACCOUNT_FULL_NAME,patindex('%[^ !-~]%' COLLATE Latin1_General_BIN,ACCOUNT_FULL_NAME),1)) as [ASCIICode]
FROM [dbo].[CLNT_SVC_GOLD_SURVEY_EMAILS_WEEKLY]
WHERE patindex('%[^ !-~]%' COLLATE Latin1_General_BIN,ACCOUNT_FULL_NAME) >0

It provided me with the following output:

CASE_NUMBER ACCOUNT_FULL_NAME       Position    InvalidCharacter    ASCIICode
02884401    GUY & O�NEILL, INC.        8        �                     63
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.