日期:2014-05-18 浏览次数:20462 次
123456789 id 1 2 3 4 5 6 7 8 9
declare @tab table(id nvarchar(2)) declare @str nvarchar(50) declare @len int declare @i int select @str='123456789' select @i=1 select @len=len(@str) while(@i<=@len) begin insert into @tab(id) values(substring(@str,@i,1)) select @i=@i+1 end select * from @tab
------解决方案--------------------
declare @str nvarchar(50) set @str='123456789' select substring(@str,number,1) col from master..spt_values where [type] = 'p' and number between 1 and len(@str) /************** col ---- 1 2 3 4 5 6 7 8 9 (9 行受影响)
------解决方案--------------------
declare @str varchar(100) set @str='123456789' select SUBSTRING(@str,s.number + 1,1) from master..spt_values s where s.type='p' and s.number <len(@str)
------解决方案--------------------
DECLARE @ID NVARCHAR(100) SET @ID = '123456789' SELECT TOP 100 ID=IDENTITY(INT,1,1) INTO #T FROM SYSOBJECTS,SYSCOLUMNS SELECT ID = SUBSTRING(@ID,ID,1) FROM #T WHERE ID <= LEN(@ID) DROP TABLE #T
------解决方案--------------------
if OBJECT_ID('tb') is not null drop table tb go declare @t varchar(800) set @t='123456789' declare @i int set @i=1 create table tb(id varchar(10)) while @i<= LEN(@t) begin insert into tb values(SUBSTRING(@t,@i,1)) -- set @t=SUBSTRING(@t,@i,@i+1) set @i=@i+1 end; select * from tb id ---------- 1 2 3 4 5 6 7 8 9 (9 行受影响)
------解决方案--------------------
declare @t varchar(800) set @t='123456789' select SUBSTRING(@t,number,1) from master..spt_values where number between 1 and LEN(@t) and type='p' ---- 1 2 3 4 5 6 7 8 9 (9 行受影响)
------解决方案--------------------
declare @s varchar(max) set @s='sfefgthg15461' select SUBSTRING(@s,number+1,1) from master..spt_values where type='p' and number<=LEN(@s)