日期:2014-05-17 浏览次数:20683 次
if object_id('[TB]') is not null drop table [TB]
go
create table [TB] (ID int,VAL int)
insert into [TB]
select 1,3 union all
select 2,4 union all
select 3,2
select * from [TB]
SELECT TB.id,TB.val,M.number+1 AS VBL
FROM dbo.TB
INNER JOIN master..spt_values M ON M.number <tb.val AND M.number >=0 AND M.type ='P'
/*
id val VBL
1 3 1
1 3 2
1 3 3
2 4 1
2 4 2
2 4 3
2 4 4
3 2 1
3 2 2*/