生成编码号001,002,003 到999

jidianxueyuan 2012-01-17 10:55:26
生成编码号001,002,003 到999动态生成999行
...全文
383 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
kingtiy 2012-01-17
  • 打赏
  • 举报
回复
个个方法都不错
水族杰纶 2012-01-17
  • 打赏
  • 举报
回复
;with t
as
(select 1 as num
union all
select num+1 from t
where num+1<=999)
select right(1000+num,3)
from t option(maxrecursion 0)
jiangshun 2012-01-17
  • 打赏
  • 举报
回复
select top 999 right('00000'+rtrim(row_number() over(order by o.name)),3) 
from sys.objects o,sys.columns c
SqlServer2008 2012-01-17
  • 打赏
  • 举报
回复

select right('00'+convert(nvarchar(4),number),3) as num
from Master.dbo.spt_values where type='p'
and number between 1 and 999
百年树人 2012-01-17
  • 打赏
  • 举报
回复
declare @i int
set @i=1
while @i<999
begin
print right('000'+ltrim(@i),3);
set @i=@i+1
end
AcHerat 2012-01-17
  • 打赏
  • 举报
回复

select right(1000+number,3) as code
from master..spt_values
where type = 'p' and number between 1 and 999
苦苦的潜行者 2012-01-17
  • 打赏
  • 举报
回复
几天怎么都是连续数字/日期啊
叶子 2012-01-17
  • 打赏
  • 举报
回复

select top 999 identity(int,1,1) as id into #t
from sys.objects o,sys.columns c
select right(1000+id,3) as num from #t
drop table #t

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧