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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:40:13+00:00 2026-05-31T10:40:13+00:00

I’m trying to develop a time sheet page on my web site, and this

  • 0

I’m trying to develop a time sheet page on my web site, and this is my database stracture:
enter image description here

I want to get total hours(TimeSheetWeeks table’s sum(timeFrom-timeTo)), total expense(TimeSheetWeeks’s table’s total amount) and total(TimSheetWeeks table’s total amount+ compAllow table’s total Amount).

This is my query I wrote to get my result:

 ;WITH w(tot, tid, eid, fd, td, am, mw) AS
 (
 SELECT   Total = tsw.amount+ca.amount , tsw.[TimeSheetID], [EmployeeID], 
 [FromDate],[ToDate],  tsw.[Amount], SUM(DATEDIFF(MINUTE, [timeFrom],[timeTo] )) 
 FROM
 TimeSheet ts 
 INNER JOIN (
  SELECT  SUM(amount) amount, TimeSheetID 
  FROM TimeSheetWeeks
  GROUP BY TimeSheetID
  )  tsw ON ts.TimeSheetID = tsw.TimeSheetID INNER JOIN (
  SELECT  SUM(amount) amount, TimeSheetID
  FROM CompAllow
  GROUP BY TimeSheetID
  )  ca ON ts.TimeSheetID = ca.TimeSheetID INNER JOIN (
     SELECT  timeFrom, timeTo, TimeSheetID
  FROM TimeSheetWeeks
  ) AS tss ON tss.TimeSheetID=ts.TimeSheetID
  WHERE ts.TimeSheetID=6
  Group By tsw.[TimeSheetID], [EmployeeID], [FromDate], [ToDate], tsw.[Amount]
  )
  SELECT tot, tid, eid, fd, td, Amount = am,  totalHrs = RTRIM(mw/60) + ':' + 
  RIGHT('0'+ RTRIM(mw%60),2)
  FROM w;

this quer causes an error saying

Column ‘ca.amount’ is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

What goes wrong here? thanx in advance.

  • 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-31T10:40:14+00:00Added an answer on May 31, 2026 at 10:40 am

    The ca.amount column is referenced in the w CTE, but is neither aggregated nor included in the GROUP BY clause:

     ;WITH w(tot, tid, eid, fd, td, am, mw) AS
     (
     SELECT   Total = tsw.amount+ca.amount , tsw.[TimeSheetID], [EmployeeID], 
     [FromDate],[ToDate],  tsw.[Amount], SUM(DATEDIFF(MINUTE, [timeFrom],[timeTo] )) 
     FROM
     TimeSheet ts 
     INNER JOIN (
      SELECT  SUM(amount) amount, TimeSheetID 
      FROM TimeSheetWeeks
      GROUP BY TimeSheetID
      )  tsw ON ts.TimeSheetID = tsw.TimeSheetID INNER JOIN (
      SELECT  SUM(amount) amount, TimeSheetID
      FROM CompAllow
      GROUP BY TimeSheetID
      )  ca ON ts.TimeSheetID = ca.TimeSheetID INNER JOIN (
         SELECT  timeFrom, timeTo, TimeSheetID
      FROM TimeSheetWeeks
      ) AS tss ON tss.TimeSheetID=ts.TimeSheetID
      WHERE ts.TimeSheetID=6
      Group By tsw.[TimeSheetID], [EmployeeID], [FromDate], [ToDate], tsw.[Amount]
      )
      SELECT tot, tid, eid, fd, td, Amount = am,  totalHrs = RTRIM(mw/60) + ':' + 
      RIGHT('0'+ RTRIM(mw%60),2)
      FROM w;
    

    Either add it to GROUP BY or change the Total expression like this:

    Total = tsw.amount + SUM(ca.amount)
    

    depending upon what is the business rule for this query.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,

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.