NULL safe fall in replacement approximations for SQLCAD 2012 2012 function
SQL Server 2012:
SELECT CONCAT(data1, data2)
PRE SQL 2012 (two solutions):
SELECT {fn CONCAT(ISNULL(data1, ''), ISNULL(data2, ''))}
SELECT ISNULL(CAST(data1 AS varchar(MAX)), '') + ISNULL(CAST(data2 AS varchar(MAX)), '')
These two solutions combine several excellent answers and caveats raised by other posters, including @Martin Smith, @Svish and @ vasin1987.
These parameters add NULL to the '' (empty line) casting to safely handle NULL when taking into account the different behavior of the + operator related to certain operands.
Note that the ODBC Scaler Function is limited to two arguments, while the + approach is scalable for many arguments as needed.
Also note the potential problem identified by @Swifty regarding the default size of varchar , here fixed by varchar(MAX) .
Troy Sheaffer Nov 21 '17 at 21:48 2017-11-21 21:48
source share