• scogeb (9/13/2012)


    Jeff Moden (9/12/2012)


    Have you tried the NOT IN without the DISTINCT?

    Also, what's with all the LTRIM/RTRIM stuff? Data should be properly stored without leading spaces and trailing spaces hardly ever matter except when determining the actual number of bytes a strinng may contain.

    Yep, same deal with NOT IN without the DISTINCT, 100% CPU for way too long.

    Who knows with the LTRIM/RTRIM. This was set up before my time here. We're trying to clean it up though. Trust me, I know it's a mess. 🙂 Take for instance the left(table2.column2,2), if you're going to use the left 2 spaces for stuff all the time, why not create another column and index it, right? I'm not sure what the original developers were thinking. Probably just wanted to get it done and go home/didn't care.

    Thanks for the help!

    What would really help us help you is if you would provide the DDL (CREATE TABLE statement) for the tables involved including the indexes currently defined on the tables. Some sample data (as INSERT INTO statements) for the tables, and the actual execution plan for the query (if possible) as a .sqlplan file.

    Right now, you are getting some help, but basically just shots in the dark.