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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:42:24+00:00 2026-05-16T02:42:24+00:00

SELECT Date_Received, DateAdd(Year, DateDiff(year, Cast(‘3/01/2010 12:00:00AM’ as DateTime) , GetDate())-1, Cast(‘3/01/2010 12:00:00AM’ as DateTime))

  • 0
SELECT Date_Received, DateAdd(Year, DateDiff(year, Cast('3/01/2010 12:00:00AM' as DateTime) , 
    GetDate())-1, Cast('3/01/2010 12:00:00AM' as DateTime)) as minimum_date
FROM [Volunteers].[dbo].[Applications]
WHERE Date_received >= DateAdd(Year, DateDiff(year, Cast('3/01/2010 12:00:00AM' as DateTime),
GetDate())-1, Cast('3/01/2010 12:00:00AM' as DateTime))

In several subqueries where I need to check that a date is within an acceptable range. I need to avoid using a simple constant as I really don’t want to update it or a config file each new school year.

My current solution is to enter the date into the query and use some complicated DATEADD tricks to get the current year(or previous year) into the date I am using in the comparison. The exact code is above. Is there a cleaner way for me to do this?

Thanks

Edit

The business requirement is to find applications submitted between 3/01 and 7/31.

We are running background checks and it costs us money for each check we do. Identifying applications submitted during this time period helps us determine if we should do a full, partial or no background check. I will also need to check if dates concerning the previous year.

We will be doing this every year and we need to know if they were in the current year. Maintaining the queries each year to update the dates is not something I want to do.

So I am looking for a good technique to keep the year parts of the dates relevant without having to update the query or a config file.

  • 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-16T02:42:25+00:00Added an answer on May 16, 2026 at 2:42 am

    If you need to query by month and year a lot, you should also consider making those properties into persisted, computed fields:

    ALTER TABLE dbo.Applications
        ADD DateReceivedMonth AS MONTH(Date_Received) PERSISTED
    
    ALTER TABLE dbo.Applications
        ADD DateReceivedYear AS YEAR(Date_Received) PERSISTED
    

    SQL Server will now extract the MONTH and YEAR part of your Date_Received and place them into two new columns. Those are persisted, e.g. stored along side with your table data. SQL Server will make sure to keep them up to date automatically, e.g. if you change Date_Received, those two new columns will be recomputed (but not on every SELECT).

    Now, your queries might be a lot easier:

    SELECT (list of fields)
    FROM dbo.Applications
    WHERE DateReceivedYear = 2010 AND DateReceivedMonth BETWEEN 3 AND 7
    

    Since these are persisted fields, you can even put an index on them to speed up queries against them!

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

Sidebar

Related Questions

Sql: select distinct DateAdd(Day, DateDiff(Day, 0, m.Receive_date), 0) as Date, (select count(*) from Raw_Mats
My Query SELECT DATE, SEC_TO_TIME( SUM( TIME_TO_SEC( `total_hours` ) ) ) AS total FROM
I have following SQL statementL: select DATE(bla), count(*) from tableA group by DATE(bla) UNION
I'd like to run statements like SELECT date_add('2008-12-31', 1) FROM DUAL Does Hive (running
SELECT Id,Date,Name FROM people WHERE DATEPART(hh,Date) >= 7 AND DATEPART(hh,Date) <= 8 Order by
For this query SELECT min(date) min_date FROM order_products group by order_id min_date ignores the
this query SELECT SUM(s.msg_sent_datetime - r.date_received) AS difference returns -743726381625992.000000 but if i add
SELECT p.INVOICE_PAYMENT_ID,i.INVOICE_ID,i.INVOICE_NUMBER,i.CLINIC_ID, i.INVOICE_DATE,i.PAYMENT_RECEIVED_DATE, i.AMOUNT, i.CURRENT_CHARGE,i.AMOUNT_RECEIVED,i.MONTH,i.YEAR,i.COMPANY_ID, i.COMPANY_NAME,c.NAME,p.NOTE,i.NOTES FROM test1 i LEFT JOIN test2 c ON
Query: SELECT col1 FROM table1 WHERE TRUNC(created_date) = TRUNC(sysdate) If the query take 10
I am building a report from information received from a muti-select form element in

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.