problems using IIf

R

Rob

In a database, I have a table with tree fields: FirstName, MiddleName
and LastName

Using a Query, I would like to get either:

Firstname & " " & MiddleName & " " & LastName (if MiddelName is not empty)

or

FirstName & " " & LastName (if MiddelName is empty)

I tried things like:

Name: IIf(IsNull[MiddleName];(FirstName & " " & LastName);(Firstname &
" " & MiddleName & " " & LastName))

but keep getting "invalid syntax" errors.

Help anyone? Much obliged.

Rob
 
J

John Spencer

Your syntax error comes from the missing parentheses () in the criteria section
of the IIF expression.

Name: IIf(IsNull([MiddleName]);FirstName & " " & LastName;Firstname &
" " & MiddleName & " " & LastName)

You could also use the following in a query.

Name: IIf([MiddleName] is Null;FirstName & " " & LastName;Firstname &
" " & MiddleName & " " & LastName)
 
T

Tom Lake

Rob said:
In a database, I have a table with tree fields: FirstName, MiddleName and
LastName
I tried things like:

Name: IIf(IsNull[MiddleName];(FirstName & " " & LastName);(Firstname & "
" & MiddleName & " " & LastName))

but keep getting "invalid syntax" errors.

Have you tried using commas instead of semi-colons to separate the
arguments?

Tom Lake
 
R

RoyVidar

Tom Lake said:
Rob said:
In a database, I have a table with tree fields: FirstName,
MiddleName and LastName
I tried things like:

Name: IIf(IsNull[MiddleName];(FirstName & " " &
LastName);(Firstname & " " & MiddleName & " " & LastName))

but keep getting "invalid syntax" errors.

Have you tried using commas instead of semi-colons to separate the
arguments?

Tom Lake

Some of us lives places where comma is used as decimalseparator. Then
comma can't be used as arguementseparator in queries and expressions
in the UI (same goes also for Excel functions), and we use semicolon
;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Concatenate Query Question... 9
Firstname plus Middlename?? 10
SQL Help 8
Contact First & Last names the wrong way around 7
Concatenate 6
SQL with IIF 5
Exporting as CSV 0
splitting a field 2

Top