CONCAT function in SQL Server

The article will explore and show you how to use the CONCAT () function in SQL Server to join multiple strings into a string.

Describe

The CONCAT function in SQL Server is used to join two or more strings into a single large string.

Syntax

To run the CONCAT function in SQL Server, we use the following syntax:

 CONCAT(chuoi1, chuoi2,. chuoi_n) 

Parameters :

  1. series1, chuoi2, . cycle : strings want to connect with each other.

Note :

  1. Input CONCAT function has a maximum length of 255 strings, a minimum of 2 strings. If only one input string is passed, CONCAT will generate an error.
  2. If passing strings without characters, CONCAT will automatically convert those values ​​into strings before joining.
  3. The CONCAT function converts NULL to an empty string in VARCHAR data type (1).
  4. The CONCAT function can only be used in later versions of SQL Server: SQL Server 2017, SQL Server 2016, SQL Server 2014, and SQL Server 2012.

For example

Take a look and explore some examples of CONCAT functions in SQL Server.

 SELECT CONCAT('Quantrimang', '.com'); 
Result: 'TipsMake.com'

SELECT CONCAT('Quan', 'tri', 'mang', '.com');
Result: 'TipsMake.com'

SELECT CONCAT('Quan ', 'Tri ', 'Mang ');
Result: 'Quan Tri Mang'

When combining strings together, you can add whitespace characters to separate your linked values ​​for easier reading.

 SELECT CONCAT('Orange', ' ', 'Peach', ' ', 'Apple'); 
Result: 'Orange Peach Apple'

In this example, Quantrimang used the second and fourth parameters in the CONCAT function to add a space character between values ​​Orange, Peach and Apple. This will help the strings not be tied together.

Previous article: CHARINDEX function in SQL Server

Next lesson: '+' operator in SQL Server

4 ★ | 2 Vote

May be interested

  • DATENAME function in SQL ServerDATENAME function in SQL Server
    the datename function in sql server returns a time value of the input argument, which can be day, month, year, quarter, hour, minute, second, millisecond ... the return value is a string type (ascii)
  • ROUND function in SQL ServerROUND function in SQL Server
    the article will give you detailed instructions on how to use the sql server round () function with the syntax and specific examples to make it easier to visualize and capture the function better.
  • CEILING function in SQL ServerCEILING function in SQL Server
    the ceiling function in sql server returns the smallest integer value greater than or equal to the transmitted numeric expression.
  • RIGHT function in SQL ServerRIGHT function in SQL Server
    the article will explore and guide you how to use the right function in sql server to extract some characters from the right side of a given string.
  • FLOOR function in SQL ServerFLOOR function in SQL Server
    the floor function in sql server returns the largest integer value but less than or equal to the transmitted numeric expression.
  • MONTH function in SQL ServerMONTH function in SQL Server
    this article will show you in detail how to use the datetime month () processing function in sql server with specific syntax and examples to better visualize and capture functions.
  • DATEDIFF function in SQL ServerDATEDIFF function in SQL Server
    this article will show you in detail how to use sql server's datetime datediff () function with syntax and specific examples to make it easier to visualize and capture functions.
  • GETUTCDATE function in SQL ServerGETUTCDATE function in SQL Server
    this article will show you in detail how to use datetime getutcdate () function in sql server with specific syntax and examples to better visualize and capture functions.
  • SQL Server YEAR functionSQL Server YEAR function
    sql server's year function returns a 4-digit integer that is the year value in the timestamp passed.
  • NULLIF function in SQL ServerNULLIF function in SQL Server
    this article will show you in detail how to use the nullif function handler in sql server with specific syntax and examples to better visualize and capture functions.