& vs +

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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

Just curious.
Thanks
 
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
 
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.
 
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.
 
Back
Top