怎么才能生成一行1 2 3 4 5 6 7 8……
怎么才能生成一行1 2 3 4 5 6 7 8…… 有没有什么直接的方法或者函数 ?
------解决方案--------------------ALTER function tmp2(@i int)
returns varchar(1000)
as
begin
declare @j varchar(1000)
declare @start int
set @start=1
set @j= ' '
while @start <=@i
begin
set @j=@j+ ' '+cast(@start as varchar)
set @start=@start+1
end
return @j
end
------解决方案--------------------不依赖于系统表的
declare @s varchar(8000)
set @s= ' '
select cast(rtrim(t1.a)+rtrim(t2.a) as int) as id into #t
from (select 0 a
union select 1
union select 2
union select 3
union select 4
union select 5
union select 6
union select 7
union select 8
union select 9)t1,
(select 0 a
union select 1
union select 2
union select 3
union select 4
union select 5
union select 6
union select 7
union select 8
union select 9)t2
select @s=@s+ ' '+rtrim(id)
from #t
order by id
set @s=stuff(@s,1,1, ' ')
print @s
drop table #t
------解决方案--------------------declare @Tab table(iid int)
declare @strTotal varchar(8000)
set @strtotal= ' '
declare @inti int
set @inti=0
while @inti <100
begin
set @inti=@inti+1
insert into @tab values(@inti)
end
select @strtotal=@strtotal+cast(iid as varchar)+ ' ' from @tab
print @strtotal