T-SQL reference › CONCAT

CONCAT and + in SQL Server

Plus joins strings. If any part is NULL, the whole thing becomes NULL. CONCAT treats NULL as empty. Use CONCAT for a display name.

A display name

SELECT customer_id,
       CONCAT(first_name, ' ', last_name) AS name,
       first_name + ' ' + last_name AS name_plus_nulls
FROM Customers;

If last_name is NULL, name_plus_nulls is NULL and the mail merge is blank. CONCAT still prints the first name.

Try it on Harbour & Co

James Rowe (Sales Manager) needs this now: “Can you resend last week’s orders with the customer’s name instead of their ID? Newest first.” Write the query, run it, send the results. Free.

Take the ticket →

Learn it on a real ticket

Monday is free on WorkSQL. A colleague’s ticket lands, you write the T-SQL, we mark it. No videos. Five minutes.

Clock in free See Monday’s tickets