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)
 Optimal compare

Author  Topic 

SamC
White Water Yakist

3467 Posts

Posted - 2003-08-28 : 15:39:18
I need to compare two Firstnames from set U1 and U2.

WHERE U1.Firstname like U2.Firstname + '%' or U2.Firstname like U1.Firstname + '%'

But that's condition has poor execution time. I need a faster solution, maybe something like

WHERE LEFT(U1.Firstname, X) = LEFT(U2.Firstname, X)

Where X is the smaller of the two lengths. (Is there a way to calculate X in the query?)

Maybe there's an even better solution out there?

Sam

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-08-28 : 16:42:16
I'm not sure that you are buying anything, but...

WHERE SUBSTRING(U1.Firstname, 1, LEN(U2.Firstname)) = U2.Firstname OR
SUBSTRING(U2.Firstname, 1, LEN(U1.Firstname)) = U1.Firstname


Tara
Go to Top of Page
   

- Advertisement -