SQL Server 2012 introduces the CONCAT function

Source: Internet
Author: User

SQL Server 2012 has added some new system functions, a brief introduction to the Concat

The CONCAT function can connect up to 255 character variables, and when you call this function you need to receive at least two arguments, the parameter type is not necessarily a string type, or it can be implicitly converted to a string type such as int, float, and so on. As long as the rules that match SQL 2012 can be implicitly converted to strings, when we want to connect two value types of data, we do not need to convert them to nvarchar and then connect by "+".

If the passed parameter is NULL, it is implicitly converted to an empty string, and if all input parameters are null, an empty string of type VARCHAR (1) is returned.

Grammar rules

SELECT CONCAT (string_value1, String_value2, String_value3 [, String_valuen])--

Instance:

DECLARE @a VARCHAR = ' Jim is now '

DECLARE @b int=10

DECLARE @c VARCHAR = ' years old '

Select CONCAT (@a, @b, @c)

Go

Returns:

Jim is now years old

The top does not use an explicit conversion to convert int to varchar, and if you don't use concat, I might need to do this.

DECLARE @a VARCHAR = ' Jim is now '

DECLARE @b int=10

DECLARE @c VARCHAR = ' years old '

SELECT @a+convert (VARCHAR, (@b)) +@c

Go;

Returns:

Jim is now years old

Below are the types of input and output parameters:

Below are the types of input and output parameters:

Input value/type

Output value/type

Sql-clr (TY PES & UDT)

NVARCHAR (MAX)

NVARCHAR (max)

NVARCHAR (max)

NVARCHAR (<=4000)

NVARCHAR (<=4000)

VARBINARY (MAX)

NVARCHAR (MA X)

All other INPUT TYPES

VARCHAR (<=8000) *unless one of the ParamEters is a NVARCHAR   of any length, the output value would being in NVARCHAR (MAX)

SQL Server 2012 There are many other new functions to join

Conversion functions
PARSE PARSE
Try_convert Try_convert
Try_parse Try_parse
Date and Time functions
Datefromparts Datefromparts
Datetime2fromparts Datetime2fromparts
Datetimefromparts Datetimefromparts
Datetimeoffsetfromparts Datetimeoffsetfromparts
EOMONTH EOMONTH
Smalldatetimefromparts Smalldatetimefromparts
Timefromparts Timefromparts
Logical functions
CHOOSE CHOOSE
Iif Iif
String functions
Concat Concat
FORMAT FORMAT
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.