--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
查看本欄目