/* 处理not null字符 */
DECLARE @t1 varchar(10) = 'a'
DECLARE @t2 varchar(10) = 'b' DECLARE @t3 varchar(10) = 'c' DECLARE @t4 varchar(10) = 'd' DECLARE @N1 int = 2012 SELECT @t1+@t2+@t3+@t4+convert(varchar(10),@N1 ) as result go/* 处理 null字符 */
DECLARE @t1 varchar(10) = 'a'
DECLARE @t2 varchar(10) = 'b' DECLARE @t3 varchar(10) = null DECLARE @t4 varchar(10) = 'd' DECLARE @N1 int = 2012SELECT @t1+@t2+ISNULL(@t3,'')+@t4+convert(varchar(10),@N1 ) as result
GO如果这里不使用isnull判断,那么我们获得的值将为null, 与我们期望的大相径庭.
---sqlserver 2012中SELECT CONCAT('a','b','c','d','2012') as result go /* 处理not null字符 */
DECLARE @t1 varchar(10) = 'a'
DECLARE @t2 varchar(10) = 'b' DECLARE @t3 varchar(10) = 'c' DECLARE @t4 varchar(10) = 'd' DECLARE @N1 int = 2012SELECT CONCAT(@t1, @t2, @t3, @t4, @N1) as result
go /* 处理 null字符 */DECLARE @t1 varchar(10) = 'a'
DECLARE @t2 varchar(10) = 'b' DECLARE @t3 varchar(10) = null DECLARE @t4 varchar(10) = 'd' DECLARE @N1 int = 2012SELECT CONCAT(@t1, @t2, @t3, @t4, @N1) as result
go