January 1, 2007 at 11:58 pm
Is there a way to not use the CROSS JOIN below? The CROSS JOIN is proving to be an expensive JOIN.
DECLARE @Comp VARCHAR(8000)
DECLARE @cComment NVARCHAR(4000)
SET @Comp = '1,2,3,4,5,6,7,8,9,10'
SET @Comp1 = CONVERT(nvarchar(4000), @Comp)
SELECT DISTINCT
FROM PRS_Txt p CROSS JOIN PRS_TSWs t
WHERE t.PerId IN (SELECT Value
FROM dbo.fnSplitString(@Comp1,','))
AND PRSStatusId = 9
AND p.Rqrd = t.TypeId
AND p.Rqrd <> 0
AND dbo.fnGetPerDate(t.PerId) BETWEEN p.StartDate AND p.EndDate
AND dbo.fnGetPerDate(t.PerId) < GETDATE()
January 2, 2007 at 12:26 am
I don't know what either table has in it nor what either is used for and you left out the SELECT list so it's really hard to tell, but first blush says just change the CROSS JOIN to an INNER JOIN and see what you get. I'd also be tempted to remove the DISTINCT.
I'd also take a look at that split string usage... WHERE IN works but is usually not as good as a good ol' fashioned join. There's absolutely no reason I can see where the function couldn't be used directly in the FROM as a "table" in the main query.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 2, 2007 at 3:08 am
January 2, 2007 at 3:48 am
What?
Then what is that:
AND p.Rqrd = t.TypeId ?
It's clear join.
And this kind of WHERE clause eliminates any chance of NULL values coming from either table.
So, you can replace CROSS JOIN with INNER JOIN ON p.Rqrd = t.TypeId.
_____________
Code for TallyGenerator
January 2, 2007 at 4:15 am
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply