Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 2nd, 2004, 11:11 AM
sneeze24 sneeze24 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 sneeze24 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
query help

ok i have 3 tables in my DB: User,Entry,Project. The User has UserName, UserID, Supervisor_ID. The Entry has ProjectID,EntryID, UserID, Total Time. The Project table has ProjectID, ProjectName(Those are the relevant columns).

A Managers group works on specific projects and the manager can see the totals of those projects broken down bymonth with this query:
SELECT Project.ProjectID, Project.ProjectName AS ProjectName,
SUM(CASE WHEN DatePart(month , WorkDate) = 1 THEN TotTime ELSE 0 END) AS Jan,
SUM(CASE WHEN DatePart(month , WorkDate) = 2 THEN TotTime ELSE 0 END) AS Feb,
SUM(CASE WHEN DatePart(month , WorkDate) = 3 THEN TotTime ELSE 0 END) AS Mar,
SUM(CASE WHEN DatePart(month , WorkDate) = 4 THEN TotTime ELSE 0 END) AS Apr,
SUM(CASE WHEN DatePart(month , WorkDate) = 5 THEN TotTime ELSE 0 END) AS May,
SUM(CASE WHEN DatePart(month , WorkDate) = 6 THEN TotTime ELSE 0 END) AS Jun,
SUM(CASE WHEN DatePart(month , WorkDate) = 7 THEN TotTime ELSE 0 END) AS Jul,
SUM(CASE WHEN DatePart(month , WorkDate) = 8 THEN TotTime ELSE 0 END) AS Aug,
SUM(CASE WHEN DatePart(month , WorkDate) = 9 THEN TotTime ELSE 0 END) AS Sep,
SUM(CASE WHEN DatePart(month , WorkDate) = 10 THEN TotTime ELSE 0 END) AS Oct,
SUM(CASE WHEN DatePart(month , WorkDate) = 11 THEN TotTime ELSE 0 END) AS Nov,
SUM(CASE WHEN DatePart(month , WorkDate) = 12 THEN TotTime ELSE 0 END) AS Dec
FROM Entry INNER JOIN [User] ON Entry.CUID = [User].CUID INNER JOIN Project ON Entry.ProjectID = Project.ProjectID
WHERE ([User].SV_CUID = @SV_CUID) GROUP BY Project.ProjectID, Project.ProjectName


if manager1 is looking at his output it looks similar to this:
ProjectName Jan Feb Mar....
Project1 10 15 5
Project2 5 20 10


now what i need is if a Director wants to view his manager groups totals similar to this:

ManagerGroup Jan Feb Mar....
Manager 1 15 25 15
Manager2 20 30 10

as you can see Manager1's monthly totals are his project totals summed together. i need a query to output the second set of data without having to add a table to my database

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > query help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT