日期:2014-05-18 浏览次数:20702 次
declare @a varchar(100) set @a='01020304050607080910111213' CREATE TABLE tb ( loubo VARCHAR(10) ) INSERT INTO tb SELECT SUBSTRING(@a,number,2) --你要切几个就添几 FROM master..spt_values WHERE type = 'P' AND number % 2 = 1 AND number <= LEN(@a) SELECT * FROM tb
------解决方案--------------------
declare @a varchar(100) set @a='01020304050607080910111213' ;with cte as ( select left(@a,2) as col,right(@a,len(@a)-2) as rcol union all select left(rcol,2),right(rcol,len(rcol)-2) from cte where len(rcol)-2 >= 1 ) select col from cte
------解决方案--------------------
declare @a nvarchar(100) declare @sql nvarchar(100) declare @i int set @a='01020304050607080910111213' set @i=1 while (@i<len(@a)) begin set @sql=substring(@a,@i,2) print @sql set @i=@i+2 end