怎么才能生成一行1 2 3 4 5 6 7 8…… 有没有什么直接的方法或者函数 ?
解决方案 »
- 正在做一个和“管家婆”类似的软件,问个业务问题,请问“单位应收应付”是应该怎么计算呢?应该用哪些单据字段加减呢
- 求一SQL语句?
- 用一条SQL语句能不能实现?请达人进!急!在线等!
- 听说您写的书<SQL Server 2000开发与管理应用实例>现在可以买到了,是吗?
- 好麻烦,这个语句是关联两个表取数据,如果有匹配就显示原始数据,没有就为0,怎么弄呢?
- 在恢复备份时出错,请帮看看呀!
- 修改已添加的链接服务器,急!!!!急!!在线等待!!
- 这个错误怎样改.
- 请问一日期型字段问题!
- 关于oracle中的SQL语句转化为sqlserver中的SQl语句的问题
- 存储过程不好用!
- 求一个select语句
set @s=''
select @s=@s+' '+rtrim(id) from #t
set @s=stuff(@s,1,1,'')
print @sdrop table #t
select '1 ','2 ','3 ','4 ','5 ','6 ','7 ','8 '
select '1 2 3 4 5 6 7 8'
select '1 ','2 ','3 ','4 ','5 ','6 ','7 ','8 '
呵呵
也不 要 依赖于系统表的 呵呵 不过谢谢大家了 哈
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(10))
set @start=@start+1
end
return @j
end
select dbo.tmp2(20)----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1234567891011121314151617181920(所影响的行数为 1 行)
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
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)t2select @s=@s+' '+rtrim(id)
from #t
order by id
set @s=stuff(@s,1,1,'')
print @sdrop table #t
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)
endselect @strtotal=@strtotal+cast(iid as varchar)+' ' from @tab
print @strtotal