first: my screenshot
What I want: the two fields here only with "Straße:" should be empty. The other four results are ok. What I have done is:
CASE WHEN "Straße/Nr." IS NOT NULL THEN ('Straße: ' + "Straße/Nr.") END
Any ideas?
It looks like the Straße/Nr value for the last two lines in the table is an empty string (''
), rather than NULL. If they were NULL, it would usually say NULL in pale or gray lettering.
You can account for this by replacing the "Straße/Nr." is not null
part of your expression with length("Straße/Nr.")>0
. Or simply add and "Straße/Nr." is not ''
. Either of the following should work:
CASE WHEN length("Straße/Nr.")>0 THEN ('Straße: ' + "Straße/Nr.") END
or
CASE WHEN "Straße/Nr." IS NOT NULL AND "Straße/Nr." is not '' THEN ('Straße: ' + "Straße/Nr.") END
On the other hand, it's possible that some of the Straße/Nr. values are actually strings with whitespace in them (eg, ' '
). In that case, use the trim
function to remove starting and ending whitespace, like this:
CASE WHEN length(trim("Straße/Nr."))>0 THEN ('Straße: ' + "Straße/Nr.") END
trim("Straße/Nr.")
. That will permanently remove any values that are just spaces, converting them into empty strings. It will also remove any extra spaces at the start or end of Straße/Nr. values, eg if you had 'Ackerstraße 86 '
it would convert it to 'Ackerstraße 86'
.