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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:37:44+00:00 2026-06-15T17:37:44+00:00

I am bit stuck with this MSSQL query and would really appreciate some help

  • 0

I am bit stuck with this MSSQL query and would really appreciate some help on this! I am trying to simply total up the number of holidays that staff have taken in a given period.

SELECT e.EMPLOYEE_ID, COUNT(y.EMPLOYEE_ID) AS TOTAL_HOLIDAYS FROM EMPLOYEE e 
LEFT OUTER JOIN
HOLIDAY y
ON e.EMPLOYEE_ID = y.EMPLOYEE_ID
WHERE e.IS_ACTIVE = 'true'
-- AND y.[DATE] BETWEEN '20121201' AND '20121210'
GROUP BY e.EMPLOYEE_ID

This query kind of gives me what I need but I want to add a filter for when the holidays are taken… I must be going about this the wrong way. I need all employees to be listed in the dataset – e.g. even if there is nothing in the HOLIDAY table then I want the result.

ID TOTAL_HOLIDAYS
1    0
2    0
etc. 

When I try to add the commented lines (I know there are no holidays between these two dates) then no rows are returned. How can I rewrite this query to always list all active EMPLOYEE_IDs and count holidays between the two dates?

  • 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-15T17:37:45+00:00Added an answer on June 15, 2026 at 5:37 pm

    Move the condition into the join:

    SELECT e.EMPLOYEE_ID, COUNT(y.EMPLOYEE_ID) AS TOTAL_HOLIDAYS
    FROM EMPLOYEE e 
    LEFT OUTER JOIN HOLIDAY y
    ON e.EMPLOYEE_ID = y.EMPLOYEE_ID
    AND y.[DATE] BETWEEN '20121201' AND '20121210'
    WHERE e.IS_ACTIVE = 'true'
    GROUP BY e.EMPLOYEE_ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a wee bit stuck on this, and was hoping you might have some
I am stuck working on a problem, and would appreciate some guidance. I am
I've come a bit stuck this afternoon with a bug in my web application
I'm a bit stuck on this - I am using a Wordpress shortcode with
hi i am a bit stuck with this. what i am going to work
I am a little bit stuck: I would like to change the max option
I have a query which I got help with but I am stuck on
I'm a bit stuck trying to get my code to output correctly, see below.
This is a bit from the query, a roster type database is looked at
I'm a bit stuck repairing a faulty table (on Hbase 0.92.1-cdh4.0.0, Hadoop 2.0.0-cdh4.0.0) There

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.