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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Avoiding or Speeding up a Cross Join

Author  Topic 

tchinedu
Yak Posting Veteran

71 Posts

Posted - 2006-09-29 : 11:41:43
Please help guys,

I have two tables

Table1
declare @Table1 Table
(
LineID int identity(1,1) primary key,
BreakerName nvarchar(255)
)
Insert into @BreakerTble (BreakerName)
select 'Collateral Types'
union all select 'Origination'
union all select 'CutOff'
union all select 'Maturity'
union all select 'Coupon'
union all select 'Ratios'
union all select 'FScores'
union all select 'DRatios'
union all select 'GeoDistribution'
union all select 'OccTypes'
union all select 'DocTypes'

Table2
declare @Table2 table
(
SerNum int Identity(1,1) primary key,
SetName varchar(255),
GrId int,
PName varchar(255),
PId int,
PItemId int,
GNumber int,
LId varchar(20),
CBalance decimal(30,2),
Rot decimal(30,20),
Mot decimal(30,20),
Lot decimal(30,20),
OBalance decimal(30,2),
PId int,
RTerm int,
SBal decimal(30,2),
PCalcId int,
PTerm int,
PMonths decimal(30,20),
)

Table 2 has thousands of row.

I want to select each row in table two with each of the straing values in table1...

I currently have it as:

SELECT ta.SetName, ta.GrId, ta.PName, ta.PId, ta.PItemId,
ta.GNumber, ta.LId, ta.CBalance, ta.Rot, ta.Mot,
ta.Lot, ta.OBalance, ta.PLId, ta.RTerm, ta.SBal,
ta.PCalcId, ta.PTerm, ta.PMonths, tb.BreakerName
From @Table2 ta
cross join @Table1 tb

this takes a little while as the records in table2 get over 20,000

is there a faster way to achieve this


Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2006-09-29 : 11:58:44
What you are describing is a cross join. This is the fastest way. I would suggest that the "little while" you are observing has little to do with execution plan and more to do with the 220,000 rows worth of data that must be spooled across your network from your server to your client.

Jay White
Go to Top of Page
   

- Advertisement -