Last answered:

06 Apr 2022

Posted on:

06 Apr 2022

0

Purpose of Coalesce line in the 2nd assignment

Hi,
For the assignment task.2 - you get a solution as below screenshot .
I'm just having trouble understanding what the purpose of Coalesce line is in the solution - what does it mean / prove?
image.png

1 answers ( 0 marked as helpful)
Instructor
Posted on:

06 Apr 2022

1

Hi Sam!
Thanks for reaching out!

IF NULL() has its limitations - it cannot contain more than two parameters. That's not the case with COALESCE(). But if COALESCE() has two arguments, it will work exactly like IF NULL(). In this particular example, we demonstrate this functionality.
Here, we check if dept_no initial value is NOT NULL and the dept_name value if it is NULL. The function returns the first of the two indicated values if the data value found in the table is not null, and returns the second value if there is a null value. Therefore, the first value is being returned here.
Hope this helps.
Best,
Ivan

Submit an answer