What I need to do is to Cartesian join the target records with a table with a certain number of records.
Create a test table and insert some records.
create table test_multiply( id int, type varchar(10), comments varchar(100) )Now we're to multiply the second record 10 times, we join the records with a table contains 9 records.
go
insert into test_multiply values ( 1, 'single', 'This row will show only once' )
insert into test_multiply values ( 2, 'times 10', 'This row will repeat 10 times' )
go
insert into test_multiplyCheck the result.
select a.* from test_multiply a
inner join ( select top 9 id from sysobjects ) x on 1=1
where a.type = 'times 10'
go
(9 rows affected)
select id, type, count(*) cnt from test_multiply group by id, typeSimilar in Oracle.
go
id type cnt
----------- ---------- -----------
1 single 1
2 times 10 10
insert into test_multiply
select a.* from test_multiply a
inner join ( select 1 from all_objects where rownum < 1="1" type =" 'times">
No comments:
Post a Comment