• Did you try the solution I provided?

    If the league table can have duplicates, keep the UNION ALL and change the league query to

    SELECT L.LeagueID as PlayerID, L.LeagueName as PlayerName

    FROM #league l

    GROUP BY L.LeagueID,L.LeagueName

    Therewith the duplicates are eliminated before union with the other result set.

    There is nothing wrong with a UNION ALL statement. A plain UNION will force a DISTINCT sort against the full result set leading to possible performance issues. Therefore, remove duplicates as early as possible in the process.

    If you simply "hate" the UNION operator, just create a staging table, insert the values returned by each single statement and run your query against that staging table. Voila! No UNION operator required!

    In the real scenario, all the unions share at least 3 tables in common.

    If the sample scenario you provided does not represent your current scenario, how would you expect our solutions to help you?

    If the query using #league would use other tables already used in the query, my solution would be different, too. But the sample data are presented as is and so is my solution.

    Keep in mind we can't look over your shoulder. All we have is what you've posted. If the original query is different, the solution most probably will be different, too.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]