Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8537097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:49:01+00:00 2026-06-11T10:49:01+00:00

I have a very simple query that is driving me absolutely nuts. Here’s the

  • 0

I have a very simple query that is driving me absolutely nuts.

Here’s the situation:

  • I have two database servers.
  • One is an old SQL Server 2000 (VM), very minimal resources.
  • The other is a very large SQL Server 2005 enterprise cluster with an absolutely ridiculous amount of resources available.
  • I have a small portion of a larger query that executes in 3 seconds and returns 50,000+ rows of data on SQL Server 2000
  • This same small query takes upwards of 15 minutes to return 1000 rows on SQL Server 2005
  • The database I’m working with is a mirror image on these two servers. Same tables, same data in tables, same indexes on tables, etc.

I’ve tried creating different indexes on the SQL Server 2005 tables, defragged all the indexes that exist, updated table statistics, etc. Nothing has been able to make this query run faster on SQL Server 2005. Currently nothing else is running against the SQL Server 2005 server, and our DBAs assure me it’s not a configuration issue or anything to do with feature deprecation between SQL Server 2000 and SQL Server 2005.

The query is below:

SELECT (CASE 
             WHEN TeamMember.ID IN  (SELECT DISTINCT ProjMgrID FROM ProjMgr)
                THEN 'Yes' 
                ELSE 'No' 
        END) AS OnProjAsMgr 
FROM TeamMember

So return a distinct list of all the ProjMgrs, and if the TeamMember is on that list then assign “Yes” to the OnProjAsMgr value.

I’m a total SQL newbie, and this is code written by a predecessor. I don’t know if there’s a better way to write it, but I cannot figure out why it runs great on SQL Server 2000 but completely implodes on SQL Server 2005.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:49:02+00:00Added an answer on June 11, 2026 at 10:49 am

    DISTINCT causes a sort, and IN causes the entire query to be evaluated. How does this version work:

    SELECT OnProjAsMgr = CASE WHEN EXISTS 
      (SELECT 1 FROM dbo.ProjMgr WHERE ProjMgrID = TeamMember.ID)
      THEN 'Yes' 
      ELSE 'No' 
      END
    FROM dbo.TeamMember;
    

    If that fares no better then I suspect indexes are missing and no query will perform well without them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple query that only returns one record. When I try
I have a very simple query (three where conditions; two equals, one between) from
I have a very simple linq query that gets data from two datatables (orderHeader
I have a very simple query that's giving me unexpected results. Hints on where
I have very simple query that calls a UDF which splits a field by
This is a very simple complexive query that I have. I need the solution.
I have a simple query that relies on two full-text indexed tables, but it
I have a very simple query that is not much more complicated than: select
I have a very simple question. I have an SQL query that looks like
I have a very simple SQL query that I made which retrieves some user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.