日期:2014-05-17 浏览次数:20410 次
--substring select substring('col',1,2) --left select left('col',2)
------解决方案--------------------
USE test GO DECLARE @long_string varchar(10) = 'abcdefg'; DECLARE @only_one_char varchar(10) = 'a' DECLARE @blank_string varchar(10) = ''; DECLARE @string varchar(10); SET @string = @blank_string; SELECT 'X'+CASE len(left(@string,2)) WHEN 2 THEN left(@string,2) WHEN 1 THEN @string + ' ' ELSE ' ' END +'X'