CONCAT function can be used to concatenate two or more strings. This function is available before in other databases like Oracle,MySQL etc. This feature will offer below advantages over standard concatenation operator(+)
The following example demonstrates a simple use case. One of the common mistakes people do is to forget to apply ISNULL when performing string concatenation. If one of the values happen to be NULL the result will be NULL too. The CONCAT function performs correct concatenation even if one of the values is NULL
ISNULL
NULL
CONCAT
DECLARE @firstname VARCHAR(20) = 'Jacob', @middlename VARCHAR(10) = NULL, @lastname VARCHAR(20) = 'Sebastian' -- Without CONCAT function SELECT @lastname + ' ' + @middlename + '' + @firstname -- Returns NULL because @middlename is NULL -- Using CONCAT function SELECT CONCAT(@lastname, ' ', @middlename, ' ', @firstname) -- returns "Sebastian Jacob"