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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:21:23+00:00 2026-06-17T18:21:23+00:00

I currently have the following sql query SELECT [Date], DATENAME(dw,[Date]) AS Day, SUM(Units) AS

  • 0

I currently have the following sql query

SELECT [Date], DATENAME(dw,[Date]) AS Day, SUM(Units) AS TotalUnits
FROM tblTimesheetEntries 
WHERE UserID = 'PJW' 
AND Date >= '2013-01-01' 
GROUP BY [Date] 
ORDER BY [Date] DESC;

Which returns the Total [Units] for a given user and date.

However I would like to produce two separate Total Units based on a new criteria i.e. whether or not the [Units] where ‘Chargeable or Not’. There is a field in tblTimeSheets called Chargeable which is a boolean (true for chargeable, false for not). How do I incorporate this to show two Sums one for each type of Units?

  • 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-17T18:21:25+00:00Added an answer on June 17, 2026 at 6:21 pm

    You can use a CASE with the SUM() to calculate the separate totals:

    SELECT [Date], 
        DATENAME(dw,[Date]) AS Day, 
        sum(case when Chargeable = 1 then Units else 0 end) ChargeableTotal,
        sum(case when Chargeable = 0 then Units else 0 end) NotChargeableTotal,
        sum(Units) AS TotalUnits
    FROM tblTimesheetEntries 
    WHERE UserID = 'PJW' 
        AND Date >= '2013-01-01' 
    GROUP BY [Date] 
    ORDER BY [Date] DESC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have the following SQL statement MySQL Query: SELECT c.day, COUNT(*) FROM calendar
I currently have the following SQL statement: SELECT s.first_name, s.last_name, tgs.group_identifier FROM staff s
I currently have the following SQL query that lists all the names of all
I have the following SQL statement: SELECT r.Result AS Resuly, COUNT(f.fieldID) AS [Count] FROM
I currently have the following query: select min(nw_lpdTEMP) AS Min_Lkpmp_Temp_C, max(nw_lpdPH) AS Max_Lkpmp_PH, (select
I have the following SQL statement: SELECT 420, DueDate, ISNULL(Amount, 0) FROM Payments WHERE
I have the following query: SELECT COUNT(employees.id) AS emp_count FROM `orders` INNER JOIN `companies`
I currently have the following Get-ChildItem -recurse -include file.ext | Select-String -pattern c: |
I currently have the following in select expert to select a bunch of fields:
Good Day, I have a PL-SQL query as follows. I'm trying to execute a

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.