Query Help - Adding a column that sums other columns

  • Greetings to the group!

    I've got a query that is doing almost everything I want it to do... Here is the query...

    SELECT

     E.PAYTYPE

    , SUM(CASE datepart(dw,E.TimeDate) WHEN 2 THEN E.Hours ELSE 0 END) as Monday

    , SUM(CASE datepart(dw,E.TimeDate) WHEN 3 THEN E.Hours ELSE 0 END) as Tuesday

    , SUM(CASE datepart(dw,E.TimeDate) WHEN 4 THEN E.Hours ELSE 0 END) as Wednesday

    , SUM(CASE datepart(dw,E.TimeDate) WHEN 5 THEN E.Hours ELSE 0 END) as Thursday

    , SUM(CASE datepart(dw,E.TimeDate) WHEN 6 THEN E.Hours ELSE 0 END) as Friday

    , SUM(CASE datepart(dw,E.TimeDate) WHEN 7 THEN E.Hours ELSE 0 END) as Saturday

    , SUM(CASE datepart(dw,E.TimeDate) WHEN 1 THEN E.Hours ELSE 0 END) as Sunday

    FROM TimeCard.dbo.TC_HOURS   E

      

    WHERE E.DEPTID in ('83810DAY','83810NGT','90510DAY','90510NGT','79410DAY','79410NGT')

    AND (E.TimeDate between '01/17/2005' and '01/23/2005')

     

    GROUP BY E.PAYTYPE

     

    The result is a grid like return that looks something like...

    Paytype  Monday

  • ?

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

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