I have this as one of the fields in my select statement:
select
...some fields
(select ISNULL( TagNames, '') from TagNames_CTE as tagNames
where Content.ID = tagNames.EntryID) as tags
from SomeTable
I noticed that even when I’m using ISNULL and telling it to replace those with empty string, I’m still getting NULL back for some records. It’s not replacing them with an empty string and I don’t see why.
I think you’ll find that the subselect actually returns NULL in those cases where no rows are found.
In cases where a row is found in
TagNames_CTEwhere thewhereclause fires andTagNamesis NULL, it will get converted to''by the function.But where no rows are found at all, the function is not called (since there are no rows for it to work its magic on) and the result of the overall subselect is NULL, because it has to return something in that column for the outer select.
An easy way to check is to run the subquery (without
ISNULL()) on its own and see if it returns a row containingNULLor no rows at all – try some simple queries along the lines of:and:
You’ll probably find that the former gives you
1, nullwhile the latter gives you1,2. Having tested that in MySQL with the following statement, you can see that this is most likely correct.