IIF used in Northwind query

johngalt47

New member
Local time
Yesterday, 22:07
Joined
Feb 9, 2017
Messages
5
I am totally lost with this usage of the IIF function. I can't figure out what is the truepart and what is the falsepart.

File As: IIf(IsNull([Last Name]),IIf(IsNull([First Name]),[Company],[First Name]),IIf(IsNull([First Name]),[Last Name],[Last Name] & ", " & [First Name]))
 
True
False

File As: IIf(IsNull([Last Name]),IIf(IsNull([First Name]),[Company],[First Name]),IIf(IsNull([First Name]),[Last Name],[Last Name] & ", " & [First Name]))

for the first IIf
 
Sometime it's also helpful to break these down into their equivalent functions where it's easier to see what they are doing. When I do that for this one I get,


Code:
Function GetName(LastName As Variant, FirstName As Variant, Company As Variant) As Variant

If IsNull(LastName) Then
     If IsNull(FirstName) Then
        GetName = Company
    Else
       GetName = FirstName
    End If
Else
    If IsNull(FirstName) Then
        GetName = LastName
    Else
        GetName = LastName & ", " & FirstName
    End If
End If

End Function
 

Users who are viewing this thread

Back
Top Bottom