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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:31:11+00:00 2026-06-08T04:31:11+00:00

I am trying to write a SQL script to fetch data for a specific

  • 0

I am trying to write a SQL script to fetch data for a specific date range. In the example shown below I am trying to pull data for 1 day (datetime) only.

But it just take more than 3 mins to complete the query execution.

I am not quite sure if I am missing any indexes to create on Datetime column. If yes could anybody please suggest me how to make this SQL query a quick execution?

Please also see the snapshots attached from query execution plan and statistics IO.

Thank you very much for your help.

The SQL query

set Statistics IO on
declare @StartDate datetime,@EndDate datetime
set @StartDate = '2012-07-19 00:00:00.000'
set @EndDate = '2012-07-20 23:59:00.000'
select * from Admin_Letters A with (nolock)
Where A.Date_Linked > @StartDate and A.Date_Linked < @EndDate

The Execution plan snapshot(s)

1.

enter image description here

2.

enter image description here

  • 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-08T04:31:15+00:00Added an answer on June 8, 2026 at 4:31 am

    With a SELECT * in your query, you will not have much luck trying to optimize anything…. since you request all columns from the table, SQL Server’s query optimizer will often go for a table scan since that’s just quicker.

    Also: table scan implies that you don’t have any clustering index on your table –> horribly bad choice. You should have a good clustering index on every real table!

    Once you have that (on e.g. an INT IDENTITY column), then you need to decide which columns you really need from that table. Put a nonclustered index on Date_Linked, and include all those columns you really truly need – something like:

    CREATE NONCLUSTERED INDEX IX01_Admin_Letters
    ON dbo.Admin_Letters(Date_Linked)
    INCLUDE (Col1, Col2, ..., ColN)   -- as **few** columns as possible!
    

    and then a

    SELECT Date_Linked, Col1, Col2, ...ColN 
    FROM dbo.Admin_Letters A
    WHERE A.Date_Linked > @StartDate AND A.Date_Linked < @EndDate
    

    will really fly! (because now, SQL Server’s query optimizer can choose to just pick a few rows from the index – and even an index scan, on a few columns, will be lots faster than a table scan)

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

Sidebar

Related Questions

I'm trying to write sql that produces the desired result from the data below.
I am trying to write a sql query like the example below, however, I
I am trying to write a data migration pl/sql script to transfer some of
I'm trying to write a SQL script to migrate data from some old table
I'm trying to write a SQL script that inserts 2 rows into a table
I'm trying to write a script which lists a directory and creates an SQL
I am trying to write a script that will copy all the data in
I'm trying to write a SQL Server database update script. I want to test
I am trying to write T-sql script which will find open records for one
I'm trying to figure out if I can write an automatic script/function/event in SQL

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.