修改一下 修改一下第一个
declare @t varchar(1000)
declare @s varchar(1000)
set @t=''
set @s = 'abcdefghijklm'
select id = identity(int,2,2) into #t from sysobjects a,sysobjects b
select @s=stuff(@s,#t.id+(#t.id % 2)-1,1,':') from #t where #t.id<len(@s)
select @s
修改一下第一个
declare @t varchar(1000)
declare @s varchar(1000)
set @t=''
set @s = 'abcdefghijklm'
select id = identity(int,2,2) into #t from sysobjects a,sysobjects b
select @s=stuff(@s,#t.id+(#t.id mod 2)-1,1,':') from #t where #t.id<len(@s)
select @s
--方法和小李哥的一样.
select id = identity(int,1,2)
into #t from sysobjects a,sysobjects b
declare @str varchar(100)
declare @s varchar(100)
set @s = 'abcdefghijklm' --被处理的字符串
set @str='' --用来存放处理后的结果
select @str=@str+':'+string
from (
select id, substring(@s, id, 2) as string
from #t
where id<=len(@s))t
set @str=substring(@str, 2, len(@str))
print @str
declare @t varchar(1000)
declare @s varchar(1000)
set @t=''
set @s = 'abcdefghijklm'
select id = identity(int,1,1) into #t from sysobjects a,sysobjects b
select @t=":"+left(@s,2),@s=stuff(@s,1,2,'') from #t where len(@s)>0
select stuff(@t,1,1,'')
declare @t varchar(1000)
declare @s varchar(1000)
set @t=''
set @s = 'abcdefghijklm'
select id = identity(int,1,1) into #t from sysobjects a,sysobjects b
seletc @t=":"+left(@s,2),@s=stuff(@s,1,2,'') from #t where len(@s)>0
select stuff(@t,1,1,'')