Home  >  Article  >  Database  >  表变量,代替临时表

表变量,代替临时表

WBOY
WBOYOriginal
2016-06-07 14:56:391233browse

一个跟临时表差不多的变量 无 declare @t table(id int identity,col varchar(4))declare @sql varchar(60)set @sql='吕布赵云马超典韦关羽张飞许褚黄忠颜良文丑庞德孙策'declare @i int;set @i=1declare @n int;set @n=2 --定义分段长度while(@ilen(@sql))be

一个跟临时表差不多的变量
declare @t table(id int identity,col varchar(4))

declare @sql varchar(60)

set @sql='吕布赵云马超典韦关羽张飞许褚黄忠颜良文丑庞德孙策'

declare @i int;set @i=1

declare @n int;set @n=2 --定义分段长度

while(@i<len(@sql))

begin

    insert into @t select substring(@sql,@i,@n)

    set @i=@i+@n
end

select * from @t
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn