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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:32:41+00:00 2026-06-18T00:32:41+00:00

I have the following query that returns < 300 results. It is currently taking

  • 0

I have the following query that returns < 300 results. It is currently taking about 4 seconds to complete, and when I look at the execution plan, it shows that it is spending 41% of resources on a clustered index scan. My limited knowledge of database administration suggests that a clustered index seek would improve performance. How can I get the query to use a clustered index seek instead of a clustered index scan? Below is the pertinent information and the query.

  • Sql Server 2008 R2
  • Table PMDME approx 140,000 rows (this is the one that is taking up 41% of resources)
  • Server Hardware: 16 core 2.7gz processors, 48gb ram
    DECLARE @start date, @end date
    SET @start = '2013-01-01'
    SET @end = CAST(GETDATE() AS DATE)
    SELECT 
        b.total,    
        c.intakes, 
        d.ships, 
        a.CODE_, 
        RTRIM(a.NAME_) as name, 
        f.employee as Salesperson,
        g.referral_type_id, 
        h.referral_type,
        e.slscode, 
        a.city, 
        a.STATE_, 
        a.zip
    FROM PACWARE.ADS.RFDME a
    LEFT OUTER JOIN (
        SELECT SUM(b.quantity) total, a.ref_id from event.dbo.sample a 
        JOIN event.dbo.sample_parts b on a.id = b.sample_id
        JOIN PACWARE.ADS.PTDME c on b.part_id = c.CODE_
        WHERE c.MEDICAREID = 'E0607' AND a.order_date between @start and @end
        GROUP BY  a.ref_id
    )b on a.CODE_ = b.ref_id
    LEFT OUTER JOIN (
        SELECT COUNT(a.CODE_)as intakes, rfcode
        FROM PACWARE.ADS.PMDME a
        WHERE a.REGDATETIME BETWEEN @start and @end
        GROUP BY a.RFCODE
    ) c on a.CODE_ = c.rfcode
    LEFT OUTER JOIN (
        SELECT
        COUNT(a.CODE) as ships, b.rfcode
        FROM
        (
            SELECT
            A.ACCOUNT AS CODE,
            MIN(CAST(A.BILLDATETIME AS DATE)) AS SHIPDATE

            FROM PACWARE.ADS.ARODME A
            LEFT OUTER JOIN PACWARE.ADS.PTDME B ON A.PTCODE=B.CODE_
            LEFT OUTER JOIN event.dbo.newdate() D ON A.ACCOUNT=D.ACCOUNT
            LEFT OUTER JOIN event.dbo.newdate_extras() D2 ON A.ACCOUNT=D2.ACCOUNT
            WHERE A.BILLDATETIME>=@start
            AND A.BILLDATETIME=@start AND D.NEWDATE=@start AND D2.NEWDATE'ID'
            Group by 
            A.ACCOUNT,
            B.MEDICAREID,
            A.CATEGORY
        ) a
        JOIN PACWARE.ADS.PMDME b on a.CODE = b.CODE_
        GROUP BY b.RFCODE
    ) d on a.CODE_ = d.rfcode
    LEFT OUTER JOIN event.dbo.employee_slscode e on a.SLSCODE = e.slscode
    JOIN event.dbo.employee f on e.employee_id = f.id
    JOIN event.dbo.referral_data g on a.CODE_ = g.CODE_
    JOIN event.dbo.referral_type h on g.referral_type_id = h.id
    WHERE total > 0 
  • 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-18T00:32:42+00:00Added an answer on June 18, 2026 at 12:32 am

    I would try creating first and index just for the colum REGDATETIME on PACWARE.ADS.PMDME table.

    GO
    CREATE NONCLUSTERED INDEX [IX_PMDME_REGDATETIME] ON PACWARE.ADS.PMDME
    (
        [REGDATETIME] ASC
    )
    GO
    

    Test how it works. I would also test adding another index to the column RFCODE (same table) if the selectivity of the column is good enough.

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

Sidebar

Related Questions

I have the following Sql Query that returns the type of results that I
I currently have the following SQL query that lists all the names of all
I have the following query that returns a comma separated list of email ids
I have following SQL query that selects some results from my table: select avg(c3),
I have the following query that returns 1738 rows: select a.street, b.id from TableA
Possible Duplicate: mysql count into PHP variable I have the following query that returns
I have following query which has select query that returns data in 5sec. But
I have the following query that returns rows based on a comma seperated list
I have the following LINQ query that returns two objects from my database. These
I have the following EF query that returns a list of usage data on

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.