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 7565665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:12:46+00:00 2026-05-30T14:12:46+00:00

Using SQL Server 2000. I have a table that receives a dump from a

  • 0

Using SQL Server 2000. I have a table that receives a dump from a legacy system once a day, I am trying to write a query that will process this table with a few reference table joins and an order by clause.

This is the SQL I have:

select  d.acct_no,
        d.associate_id,
        d.first_name,
        d.last_name,
        d.acct_bal,
        plr.long_name p_lvl,
        tlr.long_name t_lvl,
        d.category,
        d.status,
        tm.site_name,
        d.addr1 + ' ' + isnull(d.addr2,'') address,
        d.city,
        d.state,
        d.country,
        d.post_code,
        CASE WHEN d.home_phone_ok = 1 THEN d.home_phone END home_phone,
        CASE WHEN d.work_phone_ok = 1 THEN d.work_phone END work_phone,
        CASE WHEN d.alt_phone_ok = 1 THEN d.alt_phone END alt_phone,
        CASE WHEN d.email_ok = 1 THEN d.email END email,
        d.last_credit last_paid,
        d.service,
        d.quantity,
        d.amount,
        ar.area_desc area
from    item_dump d
        left outer join territory_map tm on tm.short_postcode = left(post_code,3) and country in ('United States','Canada')
        left outer join p_level_ref plr on plr.p_level_id = d.p_lvl_id
        left outer join t_level_ref tlr on tlr.t_level_id = d.t_lvl_id
        left outer join (select distinct master_item_id, site_item_id from invoice_detail) as map on map.item_id = d.item_no
        left outer join item_ref i on i.item_id = map.master_item_id
        left outer join area_ref ar on ar.area_id = i.area_id
where   (d.cat_id > 80 or d.cat_id < 70)
        and d.standing < 4
        and d.status not like 'DECEASED'
        and d.paid = 1
order by d.associate_id

Most of these columns are straight from the legacy system dump table item_dump. All the joins are only reference tables with few rows. The legacy table itself has about 17000 records but with the where statements the query comes out to 3000.

I have a non-clustered index on the associate_id column.

When I run this query without the order by associate_id clause it takes about 2 seconds. With the order by clause it takes a full minute!

I’ve tried adding the where clause columns to the index along with associate_id but that didn’t change the performance at all.

The end of the execution plan without the order by looks like this:

enter image description here

Using order by, parallelism kicks in on the order by argument and it looks like this:

enter image description here

I thought maybe it was weird SQL Server 2000 parallelism handling, but adding the (maxdop 1) hint made the query take 3 minutes instead!

It isn’t really sensible for me to put sorting in the application code because this query caches for about 6 hours before it gets run again and I would have to sort it in the application code many times a minute.

I must be missing something very basic but after straining at the query for an hour i.e. running it 10 times, I can’t see what it is anymore.

  • 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-05-30T14:12:48+00:00Added an answer on May 30, 2026 at 2:12 pm

    What happens when u remove all the outer joins and ofcourse the select’s in there..

    select  d.acct_no,
            d.associate_id,
            d.first_name,
            d.last_name,
            d.acct_bal,
            d.category,
            d.status,
            d.addr1 + ' ' + isnull(d.addr2,'') address,
            d.city,
            d.state,
            d.country,
            d.post_code,
            CASE WHEN d.home_phone_ok = 1 THEN d.home_phone END home_phone,
            CASE WHEN d.work_phone_ok = 1 THEN d.work_phone END work_phone,
            CASE WHEN d.alt_phone_ok = 1 THEN d.alt_phone END alt_phone,
            CASE WHEN d.email_ok = 1 THEN d.email END email,
            d.last_credit last_paid,
            d.service,
            d.quantity,
            d.amount
    from    item_dump d
    where   (d.cat_id > 80 or d.cat_id < 70)
            and d.standing < 4
            and d.status not like 'DECEASED'
            and d.paid = 1
    order by d.associate_id
    

    If that works fast then i would go for sub selects inside the select’s

    select  d.acct_no,
            d.associate_id,
            d.first_name,
            d.last_name,
            d.acct_bal,
            plr.long_name p_lvl,
            tlr.long_name t_lvl,
            d.category,
            d.status,
            (select tm.site_name 
             from territory_map tm 
             where tm.short_postcode = left(post_code,3) 
               and country in ('United States','Canada') as site_name
    

    etc. it’ll be really faster as left outer joining them in the from clause

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

Sidebar

Related Questions

We're using SQL Server 2000 Query Analyser, and one issue we have is that
i am using sql server 2000 .I have a table with four columns ie.
I am using SQL Server 2000 and I have two databases that both replicate
We have an old SQL table that was used by SQL Server 2000 for
I am using sql server 2000 I have a table like below : lr_no
Using SQl Server 2000 I have a stored procedure that joins 2 tables and
I have a bulk insert that works on SQL Server 2000 that I'm trying
I am using SQL Server 2000, I have a situation where I am copying
I am pretty much new to using SQL Server 2000. I have been using
We have some unit tests running against a SQL server 2000 database using the

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.