SELECT CompanyId,
CASE WHEN costcode = 'RTI' THEN SUM(exthours) END AS RTITotal,
CASE WHEN costcode = 'NRT' THEN SUM(exthours) END AS NRTTotal
FROM Timesheets
GROUP BY CompanyId
SELECT costcode, SUM(exthours) AS Expr1, CompanyId
FROM Timesheets
GROUP BY costcode, CompanyId
SELECT costcode,( SELECT SUM(exthours) from Timesheets where costcode = 'RTI') as RTITotal, (SELECT SUM(extHours) from Timesheets where costCode = 'NRT') AS NRTTOtal, CompanyId
FROM Timesheets
GROUP CompanyId
SELECT CompanyId,
CASE WHEN costcode = 'RTI' THEN SUM(exthours) END AS RTITotal,
CASE WHEN costcode = 'NRT' THEN SUM(exthours) END AS NRTTotal
FROM Timesheets
GROUP BY CompanyId
SELECT costcode, CASE WHEN costcode = 'RTI' OR costcode = 'NRT' THEN SUM(exthours) ELSE 0 END as TotalSum , CompanyId
FROM Timesheets
GROUP BY CompanyId, costcode
SELECT CompanyId, CASE WHEN costcode = 'RTI' OR costcode = 'NRT' THEN SUM(exthours) ELSE 0 END as TotalSum
FROM Timesheets
GROUP BY CompanyId
SELECT CompanyId,
CASE WHEN costcode = 'RTI' THEN SUM(ISNULL(exthours,0)) END AS RTITotal,
CASE WHEN costcode = 'NRT' THEN SUM(ISNULL(exthours,0)) END AS NRTTotal
FROM Timesheets
GROUP BY CompanyId
SELECT X.CompanyID, SUM(X.RTITotal) RTITotal, SUM(X.NRTTotal) NRTTotal
FROM (
SELECT CompanyId,
CASE WHEN costcode = 'RTI' THEN SUM(ISNULL(exthours,0)) END AS RTITotal,
CASE WHEN costcode = 'NRT' THEN SUM(ISNULL(exthours,0)) END AS NRTTotal
FROM Timesheets
GROUP BY CompanyId, costcode
) X
GROUP BY CompanyID
Title | # Comments | Views | Activity |
---|---|---|---|
SQL FUNCTION TO Capitalize Each Word in a String | 10 | 59 | |
SQl help with selection | 14 | 44 | |
SQL 2012 and SQL 2014 always on | 9 | 23 | |
SQL Server creating a temp table | 7 | 33 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
16 Experts available now in Live!