Solved

I need help!!!!

Posted on 2013-01-28
8
284 Views
Last Modified: 2013-01-28
Hi,

I have a query result.
what i want is to add up the StraighHours based on TaskStatusId
so, I need to sum up all straighthours based on the taskStatusID

Query:
                  SELECT T.TaskStatusID,WD.StraightHours, WR.CompanyID
                  FROM workdone WD
                  LEFT JOIN Task T ON WD.TaskID = T.TaskID
                  LEFT JOIN workrequest WR ON T.WRNumber = WR.WRNumber
                  LEFT JOIN MileageAndExpense ME ON WR.WRNumber = ME.WRNumber
                  where
                  WR.CompanyID = 103
                  AND ME.Billable = 'True'
                  AND (WorkDate >= '2013-01-01'
                  AND WorkDate <= '2013-01-31')
                  Group by CompanyID



My Output:
TaskStatusID  StraightHours   CompanyID
1             1.25                           103
1             0.5                          103
1            0.5                         103
1           1.5                         103
5            1                         103

the result that I want is

TaskStatusID  StraightHours   CompanyID
1             1.25                           103
1             0.5                          103
1            0.5                         103
1           1.5                         103
5            1                         103


TaskStatusID 5 is for complete task
TaskStatusID 1 is for Not completed task


HoursBilled    HoursExpectedToBeBilled
1                       3.75


Thank you!!!!!!!!!!
0
Comment
Question by:lulu50
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 16

Expert Comment

by:kmslogic
ID: 38826973
It wasn't clear what you wanted... Is it something like this?

SELECT T.TaskStatusID, WR.CompanyID, SUM(WD.StraightHours) as TotalStraightHours
                  FROM workdone WD
                  LEFT JOIN Task T ON WD.TaskID = T.TaskID 
                  LEFT JOIN workrequest WR ON T.WRNumber = WR.WRNumber
                  LEFT JOIN MileageAndExpense ME ON WR.WRNumber = ME.WRNumber
                  where 
                  WR.CompanyID = 103 
                  AND ME.Billable = 'True'
                  AND (WorkDate >= '2013-01-01'
                  AND WorkDate <= '2013-01-31')
                  Group by T.TaskStatusID, WR.CompanyID

Open in new window

0
 

Author Comment

by:lulu50
ID: 38826999
Hi kmslogic

the above query gives me this:

TaskStatusID  CompanyID   TotalStraightHours
1                 103       3.75
5                 103                       1

but what I want the output to be is this

CompanyID    HoursBilled    HoursExpectedToBeBilled
103                        1                       3.75
0
 
LVL 1

Expert Comment

by:DoutorApedeuta
ID: 38827003
The tables you posted, with your result and the result that you want are the same. Can you clarify the question?
0
Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

 

Author Comment

by:lulu50
ID: 38827010
yes they are the same
0
 
LVL 32

Accepted Solution

by:
awking00 earned 500 total points
ID: 38827058
SELECT WR.CompanyID,
SUM(CASE WHEN taskstatusid = 5 THEN WD.StraightHours ELSE 0 END) AS HoursBilled,
SUM(CASE WHEN taskstatusid = 1 THEN WD.StraightHours ELSE 0 END) AS HoursToBeBilled
FROM workdone WD
LEFT JOIN Task T ON WD.TaskID = T.TaskID
LEFT JOIN workrequest WR ON T.WRNumber = WR.WRNumber
LEFT JOIN MileageAndExpense ME ON WR.WRNumber = ME.WRNumber
WHERE WR.CompanyID = 103
  AND ME.Billable = 'True'
  AND (WorkDate >= '2013-01-01'
  AND WorkDate <= '2013-01-31')
GROUP BY CompanyID;
0
 

Author Comment

by:lulu50
ID: 38827107
awking00

this is beautifull

GREAT!!!!!!!!

THANK YOU THANK YOU AND THANK YOU
0
 

Author Closing Comment

by:lulu50
ID: 38827119
EXCELLENT!!!!!!!!!!!!!!


Thank you for a million and one.
0
 
LVL 32

Expert Comment

by:awking00
ID: 38827383
Glad to help.
0

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question