SQL Server String Concatenation with the + Operator
In SQL Server, the +
operator provides a simple way to combine (concatenate) two or more strings into a single string. This is a fundamental operation for manipulating and combining text data.
String Concatenation with +: Definition and Usage
The +
operator is a straightforward method for joining strings. It's often used to create custom text strings from individual parts, such as combining a first name and last name to form a full name, or constructing file paths from directory names and filenames.
Syntax
Syntax
string1 + string2 + ... + stringN
You can concatenate any number of strings together using the +
operator.
Related Functions
For more advanced string concatenation, explore the CONCAT()
and CONCAT_WS()
functions.
Examples
Concatenating Two Strings
This example combines "W3Schools" and ".com".
Syntax
SELECT 'W3Schools' + '.com';
Output
W3Schools.com
Concatenating Three Strings
This example combines three strings.
Syntax
SELECT 'SQL' + ' is' + ' fun!';
Output
SQL is fun!
Concatenating Strings with Spaces
Adding spaces between concatenated strings.
Syntax
SELECT 'SQL' + ' ' + 'is' + ' ' + 'fun!';
Output
SQL is fun!