Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello
I am having a few issues with an if statement in my load script.
I have a table from source with usernames where the username is blank.
I am applying an if statement evaluating any null values to have the value of 'Unknown' otherwise if the username is not null then give me the username. When I load the data in a chart table I am still getting empty values where I should be getting 'Unknown'. This causes anything else associated with the username being blank to be blank too.
The if statement I have used in my script is:
if(isnull(UserName) or UserName = '', 'Unknown', Username) as Username
I have also used a nested statement to see if I can overcome this issue which is:
if(isnull(UserName), 'Unknown',
if(UserName = '', 'Unknown', UserName)) as UserName
After using the nested if statement I am still getting blanks in a straight table and a chart table.
Can anyone know what I am doing wrong or how to overcome this?
Thanks
Hi,
You can simplify this with the following:
if( len(trim(UserName))=0, 'Unknown', UserName) as Username
But you problem maybe related to your data model.
Let us suppose that there is a table users and a table departments. If there is one department that is not associated with any user, some results will have departments but not users and that may be happening to you.
Hope this helps for now,
Regards,
Erich
Hi,
You can simplify this with the following:
if( len(trim(UserName))=0, 'Unknown', UserName) as Username
But you problem maybe related to your data model.
Let us suppose that there is a table users and a table departments. If there is one department that is not associated with any user, some results will have departments but not users and that may be happening to you.
Hope this helps for now,
Regards,
Erich
Hello Erich
Many thanks for the reply. I thought so but I will consider your code and try and use that in the future.
Thanks