SQL中如何把1笔资料重复显示成多笔,不要用循环!
假如有如下资料:
a b 4
c d 1
e f 2
--------------
我希望能查询出:
a b
a b
a b
a b
c d
e f
e f
这样的结果,谢谢大家的帮助~~~
[解决办法]
if object_id('[TB]') is not null drop table [TB]
go
create table [TB] (col1 nvarchar(2),col2 nvarchar(2),col3 int)
insert into [TB]
select 'a','b',4 union all
select 'c','d',1 union all
select 'e','f',2
select * from [TB]
SELECT col1,col2
FROM dbo.TB
INNER JOIN master..spt_values M ON TB.col3>M.number AND M.type = 'P'
/*
col1col2
ab
ab
ab
ab
cd
ef
ef*/