I have a SQL Server table containing a nvarchar(max) column. I ran a query to select every row where this column contains the string 'remove'. Amongst the results, I have several rows where this column is populated with an empty string and I don't understand why these values have been returned.
I tried to investigate further, on one of the empty string values returned. I found that the empty string value would match to certain LIKE conditions, but not others. For instance, it will match to '%remove%' and '%x%', but it won't match to '%q%'.
Within the results grid on SQL Server Management Studio, the nvarchar field is displayed as an empty field (it is not null). However, if I apply the len() function to this field, it returns the value of 649. When I export the results table from SQL Server Management Studio into Excel, the nvarchar(max) field is empty.
Assuming that there must be a bunch of whitespace characters populating the field, I tried to select the field after concatenating 'x' to either end of the value returned. In the results, the leading 'x' appears at the beginning of the string, but the 'x' concatenated onto the end is not displayed.
I'm totally confused as to what is going on. I can provide more information upon request.
select itemid, content
from objects
where itemid = 100 and content like '%remove%'
----------------
itemid | content
100 |
select itemid, 'x' + content + 'x' as 'content'
from objects
where itemid = 100 and content like '%remove%'
----------------
itemid | content
100 | x
EDIT:
Trimming the field doesn't change the character count. However, when I do use substring to select the last character in the concatenated output, the character returned is 'x', which suggests that it just isn't visible in the GUI output due to the length of the string. I still can't see this trailing 'x' character when exporting the content into Excel though. I think that there are maybe unsupported characters present within the nvarchar variable.
select itemid, 'x' + ltrim(rtrim(content)) + 'x' as 'content'
from objects
where itemid = 100 and content like '%remove%'
----------------
itemid | content
100 | x