日期:2014-05-17 浏览次数:20408 次
create table les
(料号 varchar(5), 数量 int)
insert into les
select 'A', 100 union all
select 'B', 2
select a.料号,
a.数量,
a.料号+'-'+replicate('0',3-len(c.number))+rtrim(c.number) '标签号'
from les a
cross apply
(select b.number
from master.dbo.spt_values b
where b.type='P'
and b.number between 1 and a.数量) c
/*
料号 数量 标签号
----- ----------- --------------
A 100 A-001
A 100 A-002
A 100 A-003
A 100 A-004
A 100 A-005
A 100 A-006
A 100 A-007
A 100 A-008
A 100 A-009
A 100 A-010
A 100 A-011
A 100 A-012
A 100 A-013