Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Concatenation
4. The concatenation (+) operator
Simple text functions
How to modify Strings
Summary

Instruction

Let's start off with concatenation, or the joining of two or more strings. Remember, "string" is another name for "text value".

First, we'll need a new operator, +. This plus sign is the concatenation operator. If you write the following:

SELECT
  FirstName + LastName AS Name
FROM Copywriter;

The result for FirstName = N'Kate' and LastName = N'Gordon' will be N'KateGordon'. Notice that the result is a single string.

a1

Quite simple, right? Of course, we probably want the first and the last name separated with a space. Here is how you do that:

SELECT
  FirstName + N' ' + LastName AS Name
FROM Copywriter;
a2

Note that you use single quotes for constant text values (in our example, the constant value is a space, ' ') plus the letter N to indicate that it has UNICODE encoding. You don't use quotes for column names (FirstName, LastName). The + operator can be used many times in a single query.

Exercise

For each item select its Name, Type and, in the third column, both values combined and separated with an N' - ' character. Name the column SloganType.

Observe that if Name or Type is NULL, then the SloganType is also NULL.

Stuck? Here's a hint!

Use Name + N' - ' + Type expression.