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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:17:55+00:00 2026-06-16T23:17:55+00:00

I have a query that is working fine with the exception of not calculating

  • 0

I have a query that is working fine with the exception of not calculating between certain dates. My initial Query SQL is

SELECT 
Roster.UserID, 
SchedulingLog.Category, 
Sum(IIf([CatDetail] Like '*Gain*',[Value],0)) AS Gain,
Sum(IIf([CatDetail] Like '*Used*',[Value],0))+Sum(IIf([CatDetail] Like 'Adj*',[Value],0)) AS Used,
[Gain]+[Used] AS [Left]
FROM SchedulingLog INNER JOIN Roster ON SchedulingLog.UserID = Roster.UserID
WHERE (((SchedulingLog.EventDate)>DateSerial(Year(Date()),5,20)))
GROUP BY Roster.UserID, SchedulingLog.Category
HAVING (((SchedulingLog.Category) Like "DH*" Or (SchedulingLog.Category) Like "Comp*"));

This SQL works fine until the new year. I have modified my code in the WHERE statement to use a BETWEEN qualifier, but I can not get it to work. Here is the new SQL…

SELECT
Roster.UserID,
SchedulingLog.Category,
Sum(IIf([CatDetail] Like '*Gain*',[Value],0)) AS Gain,
Sum(IIf([CatDetail] Like '*Used*',[Value],0))+Sum(IIf([CatDetail] Like 'Adj*',[Value],0)) AS Used, 
[Gain]+[Used] AS [Left]
FROM SchedulingLog INNER JOIN Roster ON SchedulingLog.UserID = Roster.UserID
WHERE (((SchedulingLog.EventDate) Between DateSerial(Year(Date()-1),5,20) And DateSerial(Year(Date()),5,20)))
GROUP BY Roster.UserID, SchedulingLog.Category
HAVING (((SchedulingLog.Category) Like "DH*" Or (SchedulingLog.Category) Like "Comp*"));

The intent of the new SQL is to gather the information between last year 5-20-2012 and this year 5-20-2013. Where am I missing the boat?

  • 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-16T23:17:56+00:00Added an answer on June 16, 2026 at 11:17 pm

    Your mistake is here:

    DateSerial(Year(Date()-1),5,20)
    

    It should be:

    DateSerial(Year(Date())-1,5,20)
    

    Just output both statements in the Immediate Window to see the difference.

    Your code (Year(Date()-1)) subtracts 1 from today’s date (3th January 2013 – 1 = 2th January 2013!!) and takes the year from that (2013), so the result is 20th May 2013.
    So you are effectively loading the data from 20th May 2013 to 20th May 2013!

    My code (Year(Date())-1) gets the year of today’s date (2013) and subtracts 1 from it (–> 2012), so the result is 20th May 2012.

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

Sidebar

Related Questions

I have a Linq to SQL query that was working just fine with SQL
I have a query with SELECT CASE statement that's working fine: SELECT (CASE `t`.`is_combined`
I have a query that is working fine when I run in through phpMyAdmin
I have a query that is working fine on my local but when placed
I have a query that is working just fine however it is a bit
I have this query (I didn't write) that was working fine for a client
I have this working query that outputs URL and click counts from database. <?php
I have below a working query that needs to be simplified. The reason is
I have inherited a somewhat messy query that I am working on refactoring to
I've got a rather lengthy query i have been working with that is throwing

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.