Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi there, here is my quesiton.table 1name_col feat1_colA 12B 10C 2...Table 2name_col feat2_colA 100B 201C 1000...Now I want to join the two tables randomly for 1000 times to get large table likefeat1_col feat2_col randomization_tag12 201 110 1000 12 100 1...12 1000 210 100 22 201 2...Is there any extreme fast way to do this work?
ms65g
Constraint Violating Yak Guru
497 Posts
Posted - 2010-05-11 : 19:13:25
for publishing lots of data you can use recursive cte and cross join like this:
declare @t1 table(i int)insert @t1 select 1 union select 2declare @t2 table(j int)insert @t2 select 100 union select 200;with rc1 as(select i,1 as l from @t1 union allselect i, l+1 from rc1 where l<100),rc2 as(select j,1 as l from @t2 union allselect j, l+1 from rc2 where l<100)select i,j,rc1.l from rc1 cross join rc2
mavershang
Posting Yak Master
111 Posts
Posted - 2010-05-11 : 20:02:00
Hi ms65g, thanks a lot for your reply.The recursive ste is a excellent idea. But after the final cross join, I feel like it is not a randomization. could you please explain that a little bit more?
quote:Originally posted by ms65g for publishing lots of data you can use recursive cte and cross join like this:
declare @t1 table(i int)insert @t1 select 1 union select 2declare @t2 table(j int)insert @t2 select 100 union select 200;with rc1 as(select i,1 as l from @t1 union allselect i, l+1 from rc1 where l<100),rc2 as(select j,1 as l from @t2 union allselect j, l+1 from rc2 where l<100)select i,j,rc1.l from rc1 cross join rc2