--sqlserver 2012之前的版本
/* 处理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 = 2012
SELECT @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 = 2012
SELECT 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 = 2012
SELECT CONCAT (@t1, @t2, @t3, @t4, @N1) as result
go
查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/database/SQLServer/