SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Detect hex 0x00 in nvarchar column


Detect hex 0x00 in nvarchar column

Author
Message
t.brown 89142
t.brown 89142
SSC-Enthusiastic
SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)

Group: General Forum Members
Points: 186 Visits: 140
Hi, this is my first post

I have a 3rd party adapter in SSIS - which gives an error "'.', hexadecimal value 0x00, is an invalid character. Line 1, position 234.". - but only when importing a particular column, so it must be something to do with the data in that column.

How can I construct a query to identify rows which contain a hex 0x00 character. Note no rows contain NULL, and most rows contain over 1000 characters in the nvarchar(MAX) column that is giving the error.

Thanks in advance for any advice
HowardW
HowardW
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2229 Visits: 9892
I did a bit of playing around and couldn't get it to work reliably with LIKE, but this worked ok with CHARINDEX:

SELECT acolumn FROM #atable WHERE CHARINDEX(NCHAR(0),acolumn)!=0


t.brown 89142
t.brown 89142
SSC-Enthusiastic
SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)

Group: General Forum Members
Points: 186 Visits: 140
Thank-you

Your code has helped me establish that a rogue hex 0x00 is not the cause of the original error. I'll raise it with the 3rd party supplier - the string however does contain cyrillic and accented characters, and possibly some Japanese - so I'm currently using the binary chop method to isolate the offending rows.


Incidentally - when trying to create some test data, I found it is quite hard to put a hex 0x00 into a string - does SQL Server use that character as a string terminator?

Compare the results of these two

SELECT 'value' + char(0) + 'more value'
SELECT 'value' + char(65) + 'more value'

The first is cut off at the char(0) character
HowardW
HowardW
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2229 Visits: 9892
Why don't you just set the SSIS package to redirect the error rows in the data flow and dump them back out to a table or file to determine which row's the culprit?

For both Unicode (UTF-8) and ASCII, 0 is defined as "NUL", which looks like a non-display character that's used as a terminator of some sort, so I'm sure it would cause issues with display...
t.brown 89142
t.brown 89142
SSC-Enthusiastic
SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)

Group: General Forum Members
Points: 186 Visits: 140
Just getting to grips with SSIS.

Redirecting error rows helped

I have now found a new error: "Could not retrieve data for column Content. Error is The value is too large to fit in the column data area of the buffer.".


But the data seemed to import anyway - I'm now checking to see if anything is truncated, but in a first pass the import seems to have worked.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search