SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select Performance issues
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

xhostx
Constraint Violating Yak Guru

USA
277 Posts

Posted - 03/20/2013 :  11:46:04  Show Profile  Reply with Quote
Performance issue, it is taking too long. And I only have 180,000 rows.
selct * from T1 a where a.id=7380
and lower(ltrim(rtrim(Last))+ltrim(rtrim(First))+ltrim(rtrim(dob))) not in
(slect lower(ltrim(rtrim(Last))+ltrim(rtrim(First))+ltrim(rtrim(dob)))
from t2 where id=7105)
Any hints please?

--------------------------
Joins are what RDBMS's do for a living

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 03/20/2013 :  11:58:44  Show Profile  Reply with Quote
problem is usage of so many function and concatination in where condition.

try this alternative


SELECT *
FROM T1 t1
WHERE id = 7380
AND NOT EXISTS (SELECT 1 FROM t2
                WHERE Last = t1.Last
                AND First = t1.First
                AND dob = t1.dob
                WHERE id = 7105)


Unless you use a case sensitive collation you dont need LOWER function logic

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

xhostx
Constraint Violating Yak Guru

USA
277 Posts

Posted - 03/20/2013 :  12:05:08  Show Profile  Reply with Quote
Visakh Thanks a lot man, that was magic :)

--------------------------
Joins are what RDBMS's do for a living
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 03/20/2013 :  13:04:57  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000