& vs +

P

PJ

What is the difference, if any, between these two operators? (When
concatenating strings).

Just curious.
Thanks
 
P

PJ

Found what I was looking for,

From MSDN
Although either symbol will work as a concatenation operator, the "+" symbol
is used as an addition operator also. If a string contains numerical
characters, the "+" symbol will causes those numbers to be added together
rather than displayed as a string. For best results, always use the "&"
symbol when you want to concatenate strings
 
M

Marshall Barton

PJ said:
What is the difference, if any, between these two operators? (When
concatenating strings).

The major difference is the way Null is propogated.
"X" + Null results in Null
"X" & Null results in "X"

This can be useful when you want to show/hide some
delimiter. E.g.
=LastName & (", " + FirstName)
will not include the comma when FirstName is Null.

It is best to use & except when you want to do something
like the above so you don't confuse it with + as the
addition operator.
 
P

PJ

Thanks, that's a useful trick to know.

Marshall Barton said:
The major difference is the way Null is propogated.
"X" + Null results in Null
"X" & Null results in "X"

This can be useful when you want to show/hide some
delimiter. E.g.
=LastName & (", " + FirstName)
will not include the comma when FirstName is Null.

It is best to use & except when you want to do something
like the above so you don't confuse it with + as the
addition operator.
 

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

Top