+ Reply to Thread
Results 1 to 2 of 2

Thread: Dynamic columns

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    13

    Dynamic columns

    I have a LaborTransaction table with the following columns:
    Code:
         Labcode |   Hours   | OTHours | Tag
         JohnS   |    2.0    |   0.0   | VACATION 
         JohnS   |    4.0    |   3.0   | PERSONAL
         JohnS   |    3.0    |   0.0   | VACATION
         JohnS   |    5.0    |   1.0   | 
         JohnS   |    7.0    |   4.0   |
    I need to generate the following table:
    Code:
    Labcode | Regular | Vacation | Personal | OT
     JohnS   |  12.0   |   5.0    |   4.0    | 8.0
    So how can i do so ?
    Last edited by lucky; 01-26-2012 at 04:15 PM.

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    20
    Code:
    select Labcode,
        sum(case when Tag = '' then Hours end) as Regular,
        sum(case when Tag = 'VACATION' then Hours end) as Vacation,
        sum(case when Tag = 'PERSONAL' then Hours end) as Personal,
        sum(OTHours) as Overtime
    from LaborTransaction 
    group by Labcode

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts