TSQL Help to calculate billable hours

  • I am trying to accomplish something very complicated or can be easy.

    I am trying to calculate total hours spent on a project and if the budget cost is more than the actual cost then get the hours that are within the budget cost.

    CASE WHEN sum(TotalBudgetCost) - sum(CurrentTotalCostTAmount)) < 0 then Sum(totalhours) * costprice

    --where sum(TotalBudgetCost) - sum(CurrentTotalCostTAmount)) > 0 --

    and this is where I am having issue with. Please let me know if I am not clear enough.

  • without more details, i'm just throwing an example out there;

    shouldn't you calculate the cost of all projects, and only filter on the criteria?

    maybe something more along the lines of this?

    SELECT

    SomeProjectID,

    SomeProjectName,

    Sum(totalhours),

    Sum(totalhours) * MIN(costprice)

    FROM SomeTable

    group by SomeProjectID,SomeProjectName

    HAVING (sum(TotalBudgetCost) - sum(CurrentTotalCostTAmount)) < 0

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply