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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:16:00+00:00 2026-05-27T05:16:00+00:00

Which is the proper way of checking events from current month on SQL Server

  • 0

Which is the proper way of checking events from current month on SQL Server and why?

1) WHERE (DATEDIFF(month, EventTime, GETDATE())=0))

2) WHERE (YEAR(EventTime) = YEAR(GETDATE()) AND MONTH(EventTime) = MONTH(GETDATE()))

Date format in table is i.e. EventTime: 2011-11-30 15:68:25.000

  • 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-27T05:16:01+00:00Added an answer on May 27, 2026 at 5:16 am

    I don’t have access to a SQL Server with a profiler, so I can’t actually give as detailed an answer as I’d like.

    The question is basically about which one allows the least calculation and most effective use of indexes.

    Variants that use string manipulation have the highest calculation load, and don’t use indexes at all. So I’ll just skip those. That leave four common expressions…

    SELECT * FROM date_sargable
    WHERE  YEAR(value) = YEAR (getDate())
      AND MONTH(value) = MONTH(getDate())
    ;
    
    SELECT * FROM date_sargable
    WHERE DATEDIFF(MONTH, value, getDate()) = 0
    ;
    
    SELECT * FROM date_sargable
    WHERE DATEDIFF(MONTH, 0, value) = DATEDIFF(MONTH, 0, getDate())
    ;
    
    
    SELECT * FROM date_sargable
    WHERE value >= DATEADD(MONTH, DATEDIFF(MONTH, 0, getDate())    , 0)
      AND value <  DATEADD(MONTH, DATEDIFF(MONTH, 0, getDate()) + 1, 0)
    ;
    

    The first three use INDEX SCANs, but the last one uses an INDEX SEEK. The difference is that the format of the query allows the optimiser to know you want a specific range of the data, that it’s all next to each other in one block of the index, and that it’s very easy to find that block.

    If, when looking at execution plans, you see a SEEK in one version, and a SCAN in another, you’re much more likely to benefit from the SEEK.

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

Sidebar

Related Questions

What will be proper way to catch exception which throw SQL server when I
Is this the proper way to detect which device a user is running? NSString
Windows 6 (Vista and Server 2008) support proper symbolic links, which can be created
I am trying to find out which is the proper way to fetch data
Is there a proper way to rebind events in JQuery UI when tabs are
Question: Which of these is the proper way to nest the <h1> and <article>
In the contrived example below, which is the proper way to name my [Nn]ame
Which of these two is the proper way to wire up change-notification for the
I have two questions for you guys: Which is the proper way ot word-wrap
Just to know. Which is the proper way of ordering import statements? Also which

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.