Query to get the total effort Projectwise

I have the following table
create table Allocation
  projID varchar(10),
  projName varchar(20),
  associateID number,
  associateName varchar(10),
  allocationStartDate Date,
  allocationEndDate Date,
  allocationPercent number
  PRIMARY KEY(associateID,associateName)
insert into Allocation values ('123','Mr.A','Prj1','Green Computing','to_date('05/15/2011', 'mm/dd//yyyy')','to_date('07/15/2011', 'mm/dd//yyyy')','50');
insert into Allocation values ('123','Mr.A','Prj2','Cloud Computing','to_date('05/31/2011', 'mm/dd//yyyy')','to_date('06/30/2011', 'mm/dd//yyyy')','70');
insert into Allocation values ('1234','Mr.B','Prj1','Green Computing','to_date('06/15/2011', 'mm/dd//yyyy')','to_date('07/31/2011', 'mm/dd//yyyy')','60');
create table Project
  projID varchar(10),
  projName varchar(20),
  StartDate Date,
  EndDate Date,
  PRIMARY KEY(associateName)
insert into Project values ('Prj1','Green Computing','to_date('05/01/2011', 'mm/dd//yyyy')','to_date('07/31/2011', 'mm/dd//yyyy')');
insert into Project values ('Prj2','Cloud Computing','to_date('05/15/2011', 'mm/dd//yyyy')','to_date('08/31/2011', 'mm/dd//yyyy')');I want to select the project wise efforts. i.e. The number of working days multiplied by the 9hrs for each day for all the associates under a project. The result should look something like this
Project ID     Project Name     Associate ID     Associate Name     Effort
Prj1             Green Computing     123                Mr.A            100
Prj1             Green Computing     1234                Mr.B            120Oracle version : 9i 10g/11g

I have made my attempt at mind reading (to correct for errors in script). Do you mean the following:
CREATE TABLE Allocation
   associateID           VARCHAR (10),
   associateName         VARCHAR (100),
   projID                VARCHAR (10),
   projName              VARCHAR (20),
   allocationStartDate   DATE,
   allocationEndDate     DATE,
   allocationPercent     NUMBER,
   CONSTRAINT pk_allocation PRIMARY KEY (associateID, ProjID)
INSERT INTO Allocation
     VALUES ('123',
             'Mr.A',
             'Prj1',
             'Green Computing',
             TO_DATE ('05/15/2011', 'mm/dd/yyyy'),
             TO_DATE ('07/15/2011', 'mm/dd/yyyy'),
             '50');
INSERT INTO Allocation
     VALUES ('123',
             'Mr.A',
             'Prj2',
             'Cloud Computing',
             TO_DATE ('05/31/2011', 'mm/dd/yyyy'),
             TO_DATE ('06/30/2011', 'mm/dd/yyyy'),
             '70');
INSERT INTO Allocation
     VALUES ('1234',
             'Mr.B',
             'Prj1',
             'Green Computing',
             TO_DATE ('06/15/2011', 'mm/dd/yyyy'),
             TO_DATE ('07/31/2011', 'mm/dd/yyyy'),
             '60');
COMMIT;
CREATE TABLE Project
   projID      VARCHAR (10),
   projName    VARCHAR (20),
   StartDate   DATE,
   EndDate     DATE,
   CONSTRAINT pk_project PRIMARY KEY (projID)
INSERT INTO Project
     VALUES ('Prj1',
             'Green Computing',
             TO_DATE ('05/01/2011', 'mm/dd/yyyy'),
             TO_DATE ('07/31/2011', 'mm/dd/yyyy'));
INSERT INTO Project
     VALUES ('Prj2',
             'Cloud Computing',
             TO_DATE ('05/15/2011', 'mm/dd/yyyy'),
             TO_DATE ('08/31/2011', 'mm/dd/yyyy'));
COMMIT;
SELECT a.projid "Project ID",
       p.projname "Project Name",
       a.associateid "Associate ID",
       a.associatename "Associate Name",
       CASE
          WHEN a.allocationenddate - a.allocationstartdate >= 0
          THEN
              /*if project begins and ends on the same day,
                we still want to allocate 9 hrs,
                so we use a "1 + " to account for the first day*/
              to_char((1 + (a.allocationenddate - a.allocationstartdate) * 9))
          WHEN a.allocationenddate is null or a.allocationstartdate is null
          THEN
             /*if project is still underway*/
             'Project is in progress'
          WHEN a.allocationenddate - a.allocationstartdate < 0
          THEN
              /*begin date is later than end date*/
             'Invalid data - begin date must occur before end date'
          ELSE
           null
       END
          "Effort"
  FROM allocation a
  JOIN project p
  ON a.projid = p.projid;

Similar Messages

  • How to write a query to get the total as a last row

    Hi,
    I need to get something like this ....
    |TEAM LEADER| TEAM | OCT TRN | EMPS| YTD% |
    |_____________|__________|__________|______|_______|
    | JOHN | JD Team | 12 | 12 | 100 |
    |_____________|__________|__________|______|_______|
    | Total |      | 12 | 12 | 100 |
    |_____________|__________|__________|______|_______|
    I have to get the last row as total adding the number columns ...
    Thanks in advance ...

    Take a look at the GROUP BY ROLLUP feature:
    create table t1
    (team_name      varchar2(30)
    ,wins           number
    ,losses         number
    insert into t1 values ('Hornets',3,1);
    insert into t1 values ('Panthers',4,0);
    insert into t1 values ('Wolves',2,2);
    insert into t1 values ('Badgers',0,4);
    insert into t1 values ('Hornets',1,3);
    commit;
    select decode(team_name,
                 NULL,'TOTAL',
                 team_name) team_name, sum(wins), sum(losses)
    from   t1
    group by rollup(team_name);
    TEAM_NAME                                 SUM(WINS)          SUM(LOSSES)
    Badgers                                           0                    4
    Hornets                                           4                    4
    Panthers                                          4                    0
    Wolves                                            2                    2
    TOTAL                                            10                   10

  • DLookUp Referencing a Query To Get a Total Amount Owed

    I have a form named: Branch 142 Membership that has a text box named: TextBoxTotalAmountDueToDate. The control source is: =DLookUp("[Total Amount Due]","[QryTotalAmtDueBy]","[MemberID]=" & [Forms]![Branch 142 Membership]![MemberID])
    I'm getting the sum total for all of the records in my database that is the sum for just one member. There's one payment record in the Payments table. Of course when I open the query I get the total for the one payment record.
    I want to get the Sum([PPUnionDuesAmountNoDeduct]-[PaymentAmount]) for each record in the object: TextBoxTotalAmountDueToDate.  If the amount is zero I want the text box to display zero. When I entered =Sum([PPUnionDuesAmountNoDeduct]-[PaymentAmount])
    I got an error in text box.
    Thanks for the help.

    I will try again. For example, I have a table (Payments) that has 5 records. The 5 Payments table records has $24.45 entered all for the same person, Billy Bob that totals $122.25. I have a table (Members) that Billy Bob is one of 10 records. The query:QryTotalAmtDueBy
    returns 1 result (record) and it is only for Billy Bob for $122.25 because he is the only one entered in the Payments table. Total Amount Due: Sum([PaymentAmount]-[PPUnionDuesAmountNoDeduct])
    When I enter into the control source for text box:
    TextBoxTotalAmountDueToDateTab5 the expression: =DLookUp("[Total Amount Due]","[QryTotalAmtDueBy]","[MemberID]=" & [Forms]![Branch 142 Membership]![MemberID]) on the form: Branch 142 Membership. I get the
    $122.25 total amount due for Billy Bob and for the remaining 9 records in the
    TextBoxTotalAmountDueToDateTab5.
    You suggested I try =DLookUp("Total Amount Due","QryTotalAmtDueBy"). I get #Error when I entered it in the text box:
    TextBoxTotalAmountDueToDateTab5. I modified what you gave me and entered: =DLookUp("[Total Amount Due]","[QryIndivTotalAmtDueBy]"). I still get the
    $122.25 total amount due for Billy Bob and for the remaining 9 records in the Members table.
    I don’t care if I use a control source that references the
    Total Amount Due from the query QryTotalAmtDueBy or if I use a control source expression that is the sum
    of the PaymentAmounts minus the sum of the PPUnionDuesAmountNoDeduct for each record in the Members table. I've tried:
    =IIf(IsNull([MemberID]),0,DSum("[PPUnionDuesAmountNoDeduct]-[PaymentAmount]","Payments","[MemberID]=" & [MemberID])). I get nothing for
    any record in the Members table.

  • How to get the total execution time from a tkprof file

    Hi,
    I have a tkprof file. How can I get the total execution time. Going through the file i guess the sum of "Total Waited" would give the total time in the section "Elapsed times include waiting on following events:"
    . The sample of tkprof is given below.
    SQL ID: gg52tq1ajzy7t Plan Hash: 3406052038
    SELECT POSTED_FLAG
    FROM
    AP_INVOICE_PAYMENTS WHERE CHECK_ID = :B1 UNION ALL SELECT POSTED_FLAG FROM
      AP_PAYMENT_HISTORY APH, AP_SYSTEM_PARAMETERS ASP WHERE CHECK_ID = :B1 AND
      NVL(APH.ORG_ID, -99) = NVL(ASP.ORG_ID, -99) AND
      (NVL(ASP.WHEN_TO_ACCOUNT_PMT, 'ALWAYS') = 'ALWAYS' OR
      (NVL(ASP.WHEN_TO_ACCOUNT_PMT, 'ALWAYS') = 'CLEARING ONLY' AND
      APH.TRANSACTION_TYPE IN ('PAYMENT CLEARING', 'PAYMENT UNCLEARING')))
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute    442      0.08       0.13          0          0          0           0
    Fetch      963      0.22       4.72        350      16955          0         521
    total     1406      0.31       4.85        350      16955          0         521
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 173     (recursive depth: 1)
    Number of plan statistics captured: 1
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
             1          1          1  UNION-ALL  (cr=38 pr=3 pw=0 time=139 us)
             1          1          1   TABLE ACCESS BY INDEX ROWID AP_INVOICE_PAYMENTS_ALL (cr=5 pr=0 pw=0 time=124 us cost=6 size=12 card=1)
             1          1          1    INDEX RANGE SCAN AP_INVOICE_PAYMENTS_N2 (cr=4 pr=0 pw=0 time=92 us cost=3 size=0 card=70)(object id 27741)
             0          0          0   NESTED LOOPS  (cr=33 pr=3 pw=0 time=20897 us)
             0          0          0    NESTED LOOPS  (cr=33 pr=3 pw=0 time=20891 us cost=12 size=41 card=1)
             1          1          1     TABLE ACCESS FULL AP_SYSTEM_PARAMETERS_ALL (cr=30 pr=0 pw=0 time=313 us cost=9 size=11 card=1)
             0          0          0     INDEX RANGE SCAN AP_PAYMENT_HISTORY_N1 (cr=3 pr=3 pw=0 time=20568 us cost=2 size=0 card=1)(object id 27834)
             0          0          0    TABLE ACCESS BY INDEX ROWID AP_PAYMENT_HISTORY_ALL (cr=0 pr=0 pw=0 time=0 us cost=3 size=30 card=1)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      db file sequential read                       350        0.15          4.33
      Disk file operations I/O                        3        0.00          0.00
      latch: shared pool                              1        0.17          0.17
    ********************************************************************************

    user13019948 wrote:
    Hi,
    I have a tkprof file. How can I get the total execution time.
    call count cpu elapsed disk query current rows
    total 1406 0.31 4.85 350 16955 0 521TOTAL ELAPSED TIME is 4.85 seconds from line above

  • How to get the total record count for the report

    Hi,
    How can I get count of the total records shown in the report. When we set the report attributes, we have an option "Set Pagination from X to Y of Z"
    Does anyone know how can I get the Z value from APEX variables.
    I know we can use that query and get the count but I just want to know how we can use APEX Variables effectively.
    Thanks in advance.

    You write a loop, something like this:
    Go_block('B1');
    If not form_success then
      Raise Form_Trigger_failure;
    End if;
    First_Record;
    If not form_success then
      Raise Form_Trigger_failure;
    End if;
    Loop
      If :system.record_status in('CHANGED','INSERT') then
        -- modify the record here--
      End if;
      Exit when :System.Last_Record = 'TRUE';
      Next_Record;
    End Loop;
    First_Record;But be very careful-- If your block can fetch a large number of rows, (over 100), this loop can take a long time, and you should not use this method. The loop will continue fetching more rows from the database until all rows satisfying the query are retrieved.

  • How to get the total record count in ODI

    Hi
    I have the interface the are file to DB.
    The format is like this..
    HEADER
    DETAIL
    TRAILER
    Now will write the contains of file to DB,
    But i have to insert the total count ie numberof record written from file to DB in my Trailer record.
    can you tell me how can i get the total count of records in file and write it to trailer?
    Also, I want the interface to rollback the data if something fails will loading the data from file., ie. if there are 100 records in file and 50 got transfer and something fails i want to rollabck the 50 records from DB.???
    Thanks :)

    Hi
    You can design a flow for Full load flow and incremental flow from flat file to Table.
    Create a table at target database like.. (create table with last_execution and palce the V_FULL_LOAD value and LAST_EXECUTION_DT columns in last_execution table)
    Add faltfile as table in model, create a variable as V_FULL_LOAD and make sure that the default values is 01-01-1900
    Create one more variable like V_LAST_EXECUTION_DATE (in this variable write a case statement that if V_FULL_LOAD value is 'Y" then full load should happen and same time you should check that V_FULL_LOAD column is balnk then write insert statment else write update statement to update last_execution_dt column, similar for 'N')
    please provide your *personal mail ID*, i will send a doc file realted to your query.
    we have to tables present in work repository (SNP_STEP and STEP_LOG tables) using tables we can get how many records are inserted/updated and we can find how many records are not transfer and gor error.
    Thanks
    Phani

  • RQL Query to get the specific range of product items from product catalog.

    Hi All,
    I need to do the batch wise query to product catalog.
    For that i have use Query builder but that is giving me repeated items, now i wanted to use RQL using rqlStatement.
    Please help me in solving the issue.
    Query which i have used using QueryBuilder.
                    RepositoryView productView = productRepo.getView("product");          
                    QueryBuilder productBuilder = productView.getQueryBuilder();
                    Query productQuery = productBuilder.createUnconstrainedQuery();           
                    RepositoryItems[] productItems = productView.executeQuery(productQuery,startIndex,endIndex);
    Can anybody help me in writing RQL Query to get the specific range of product items from product catalog.

    Hi Shakuntala,
    There is no executeQuery method defined in RqlStatement Interface, which will accept index for output result.
    So As far as I know, what u are trying to achieve is not possible with RQL statements OOTB way.U can consider range of results based on some condition from Repository items.
    Please let me know if u find any way to implement it.
    Above Query builder should always return different ids if range is not overlapping with previous range.
    Please verify that repeated items ids are same or different,
    Quoting from API docs:
    RepositoryItem[] executeQuery(Query pQuery,
                                  int pStartingIndex,
                                  int pEndingIndex)
                                  throws RepositoryException
        Executes the given query and returns an array of matching RepositoryItems, which are contained within a total potential result set. For example used if one wanted to retrieve elements 50-60 from a query which could return 100 elements.
    Regards,
    Nitin.

  • Query to get the po amount from the pr

    Hi
    how to get the POnumber and PO amount from the Pr number. there are hundred's of PO's raise against the PR's
    and want to know the amount from their PO's to know the avaible fund left with the department.
    Regards
    Arifuddin

    Hi Madhan,
    If you talking abt query to find the total sal of each employee i.e., SAL + CUMSAL then you can use the below query:
    select a.empno,a.ename,a.sal + b.cumsal totalsal from
    emp a, emp b
    where a.empno = b.empno;
    Regards,
    Murali Mohan

  • Query to get the Excise amount and basic amount based on the cst or vat tax

    Dear all,
                       I need a right query to get the basic amount ,excise amount and the tax amount based on the CST or VAT tax rate.The output should be like this,
    VAT
    goods excisabe at 1% - taxable amt(basic+excise for vat 1%)            tax amt
    goods excisable at 4%-   txable amt                                                       tax amt
    CST
    goods excisabe at 1% - taxable amt(basic+excise for CST 1%)            tax amt
    My problem will also be solved..if i am able to get  the basic value from base table OPCH itself............Since am using the PCH1 table to get the total basic amt...the values are duplicating.
    Regards,
    Shyam

    Hi Sowjanya,
    If you're simply trying to place a grand total, use the 'Insert Summary' option.
    Choose the measure field as the 'Field to Summarize' > Choose 'Sum' as the summary operation > Under 'Summary Location' choose 'Grand Total Report Footer'.
    -Abhilash

  • How to get the total bytes read by windows media palyer?

    Using the wmp activeX control to play an avi format file, and using cvi's activeX tools to generate a wmp control. It can play. I'd like to know which method can get the bytes that read by wmp?
    Thanks.

    user13019948 wrote:
    Hi,
    I have a tkprof file. How can I get the total execution time.
    call count cpu elapsed disk query current rows
    total 1406 0.31 4.85 350 16955 0 521TOTAL ELAPSED TIME is 4.85 seconds from line above

  • Query to get PO total amount

    Hi,
    I want to do a query to get PO total value(sum of line item value), how to do that?
    In EKPO, it will show PO+Line item value, but the user requirement is to see PO total value under 5000 local currency.
    Please help, thanks.

    I will try again. For example, I have a table (Payments) that has 5 records. The 5 Payments table records has $24.45 entered all for the same person, Billy Bob that totals $122.25. I have a table (Members) that Billy Bob is one of 10 records. The query:QryTotalAmtDueBy
    returns 1 result (record) and it is only for Billy Bob for $122.25 because he is the only one entered in the Payments table. Total Amount Due: Sum([PaymentAmount]-[PPUnionDuesAmountNoDeduct])
    When I enter into the control source for text box:
    TextBoxTotalAmountDueToDateTab5 the expression: =DLookUp("[Total Amount Due]","[QryTotalAmtDueBy]","[MemberID]=" & [Forms]![Branch 142 Membership]![MemberID]) on the form: Branch 142 Membership. I get the
    $122.25 total amount due for Billy Bob and for the remaining 9 records in the
    TextBoxTotalAmountDueToDateTab5.
    You suggested I try =DLookUp("Total Amount Due","QryTotalAmtDueBy"). I get #Error when I entered it in the text box:
    TextBoxTotalAmountDueToDateTab5. I modified what you gave me and entered: =DLookUp("[Total Amount Due]","[QryIndivTotalAmtDueBy]"). I still get the
    $122.25 total amount due for Billy Bob and for the remaining 9 records in the Members table.
    I don’t care if I use a control source that references the
    Total Amount Due from the query QryTotalAmtDueBy or if I use a control source expression that is the sum
    of the PaymentAmounts minus the sum of the PPUnionDuesAmountNoDeduct for each record in the Members table. I've tried:
    =IIf(IsNull([MemberID]),0,DSum("[PPUnionDuesAmountNoDeduct]-[PaymentAmount]","Payments","[MemberID]=" & [MemberID])). I get nothing for
    any record in the Members table.

  • How can I get the total "values" in a hashtable ?

    i know that i can get the total values in a hashtable by hash.elements() method. It returns an
    enumeration with all the values present in this hashtable. this is fine upto here.
    Now the preoblem is:
    According to what rule this enumeration will be returned. I mean..
    If i added in key A with value a,
    then key B with value b;
    then key C with value c;
    then key D with value d;
    (They all are objects of type String)
    now i call ... hash.elements(); Suppose it returns Enumeration enum;.
    Now in what order they all are present in this hashtable.
    Meaning is that if i move arond this enum in what sequence they all will be returned.
    option A ) In the same order as they were inserted in hashtable.
    option B ) According to LIFO;
    option C) There is no fix rules , simply it return all the elements and u cannot judge that the first element in enum was really the first element inserted in the hashtable and the second element of enum was really the second element inserted in the hashtable.
    What do u think..which option is correct ?
    Ny idea will highly appreciated.
    Thanks in advance.
    Sanjeev Dhiman

    hi, i am again..
    boss ! this is not true..u just change the order and or change the keys and something like ...
    "Sanjeev", "hello"
    "Dhiman", "hi"
    "Technosys" ,"Services"
    u will find that its not LIFO..really i was thinking before coding my project that option A is correct and with knowledge i wrote 3 - 4 classes but when i run the programm its starts throwing errors.
    so, i posted this question. I think "apppu" is right.
    I think , firstly hash is calculated for each value and that value is returned which can be received in a fastest way and hence not necessarily in LIFO and FIFO..
    Thanks to u also as u gave ur precious time for me.
    Once again.
    Thank you very much.
    Sanjeev Dhiman

  • How To Get The Total Delivered Quantity of a Sales Order

    Hello All,
    I have a requirement of getting the total delivery quantity of the sales order .I have checked it in LIps table but I am getting partially delivered quantity for a schedule line item.Can any one tell me how to get the total delivered quantity.
    Regards,
    Pavani.

    Hi
    Check the Table:
    VBEP  - Sales Document: Schedule Line Data.
    Inside the table check the Quantity Fields.
    Regards,
    Sreeram

  • Query to get the data of all the columns in a table except any one column

    Can anyone please tell how to write a query to get the data of all the columns in a table except one particular column..
    For Example:
    Let us consider the EMP table.,
    From this table except the column comm all the remaining columns of the table should be listed
    For this we can write a query like this..
    Select empno, ename, job, mgr, sal, hiredate, deptno from emp;
    Just to avoid only one column, I mentioned all the remaining ( 7 ) columns of the table in the query..
    As the EMP table consists only 8 columns, it doesn't seem much difficult to mention all the columns in the query,
    but if a table have 100 columns in the table, then do we have to mention all the columns in the query..?
    Is there any other way of writing the query to get the required result..?
    Thanks..

    Your best best it to just list all the columns. Any other method will just cause more headaches and complicated code.
    If you really need to list all the columns for a table because you don't want to type them, just use something like...
    SQL> ed
    Wrote file afiedt.buf
      1  select trim(',' from sys_connect_by_path(column_name,',')) as columns
      2  from (select column_name, row_number() over (order by column_id) as column_id
      3        from user_tab_cols
      4        where column_name not in ('COMM')
      5        and   table_name = 'EMP'
      6       )
      7  where connect_by_isleaf = 1
      8  connect by column_id = prior column_id + 1
      9* start with column_id = 1
    SQL> /
    COLUMNS
    EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO
    SQL>

  • How to modify the query to get the output in a single row

    Hi All,
    Below is the query i have written it works fine
    select DISTINCT right(left(CTACCT,13),4) AS LocationNum,
    tODS_GLBalance.FiscalYearId AS FiscalYearId,
    tODS_GLBalance.FiscalMonthOfYearId AS FiscalMonthOfYearId,
    --tods_GLMetadata.Metric,
    Case when
    tods_GLMetadata.Metric = 'Gross Margin'
    Then SUM(Balance)
    Else 0
    END AS GrossMargin,
    Case when
    tods_GLMetadata.Metric = 'Occupancy'
    Then SUM(Balance)
    Else 0
    END AS Occupancy,
    Case when
    tods_GLMetadata.Metric = 'Payroll Dollars'
    Then SUM(Balance)
    Else 0
    END AS Payroll,
    Case when
    tods_GLMetadata.Metric = 'CF Sales'
    Then SUM(Balance)
    Else 0
    END AS OperatingSales,
    Case when
    tods_GLMetadata.Metric = 'Operations'
    Then SUM(Balance)
    Else 0
    END AS OperatingExpenses
    -- 0 as payroll
    from ods.[JJill].[tODS_GLBalance]
    inner join ods.Staging.tODS_INF_GLPCT ON tODS_GLBalance.PageNum = tODS_INF_GLPCT.CTPAGE
    inner join ods.JJill.tods_GLMetadata ON tods_GLMetadata.AcctDescription = tODS_INF_GLPCT.CTDESC
    where
    (tODS_GLBalance.FiscalYearId = 2012) and
    (tODS_GLBalance.FiscalMonthOfYearId = 2) and
    (right(left(CTACCT,13),4)= 3020)
    group by
    right(left(CTACCT,13),4),
    tODS_GLBalance.FiscalYearId,
    tODS_GLBalance.FiscalMonthOfYearId,
    tods_GLMetadata.Metric
    This is the sample output,
    LocationNum FiscalYearId FiscalMonthOfYearId GrossMargin Occupancy Payroll OperatingSales OperatingExpenses
    3020 2012 2 -112477.00 0.00 0.00 0.00 0.00
    3020 2012 2 0.00 0.00 0.00 -158288.94 0.00
    3020 2012 2 0.00 0.00 0.00 0.00 5625.44
    3020 2012 2 0.00 0.00 24185.79 0.00 0.00
    3020 2012 2 0.00 31075.53 0.00 0.00 0.00
    But, i am expecting the output to be something like this
    LocationNum FiscalYearId FiscalMonthOfYearId GrossMargin Occupancy Payroll OperatingSales OperatingExpenses
    3020 2012 2 -112477.00 31075.53 24185.79 -158288.94 5625.44
    Can someone please help me with changing my query to get the desired output?
    Please let me know if you have any questions.
    Thanks

    Try this:
    SELECT DISTINCT
    RIGHT(LEFT(CTACCT,13),4) AS LocationNum, tODS_GLBalance.FiscalYearId AS FiscalYearId, tODS_GLBalance.FiscalMonthOfYearId AS FiscalMonthOfYearId,
    SUM(CASE WHEN tods_GLMetadata.Metric = 'Gross Margin' THEN Balance ELSE 0 END ) AS GrossMargin,
    SUM(CASE WHEN tods_GLMetadata.Metric = 'Occupancy' THEN Balance ELSE 0 END ) AS Occupancy,
    SUM(CASE WHEN tods_GLMetadata.Metric = 'Payroll Dollars' THEN Balance ELSE 0 END ) AS Payroll,
    SUM(CASE WHEN tods_GLMetadata.Metric = 'CF Sales' THEN Balance ELSE 0 END ) AS OperatingSales,
    SUM(CASE WHEN tods_GLMetadata.Metric = 'Operations' THEN Balance ELSE 0 END ) AS OperatingExpenses
    FROM ods.[JJill].[tODS_GLBalance]
    INNER JOIN ods.Staging.tODS_INF_GLPCT
    ON tODS_GLBalance.PageNum = tODS_INF_GLPCT.CTPAGE
    INNER JOIN ods.JJill.tods_GLMetadata
    ON tods_GLMetadata.AcctDescription = tODS_INF_GLPCT.CTDESC
    WHERE tODS_GLBalance.FiscalYearId = 2012
    AND tODS_GLBalance.FiscalMonthOfYearId = 2
    AND RIGHT(LEFT(CTACCT,13),4) = 3020
    GROUP BY right(left(CTACCT,13),4), tODS_GLBalance.FiscalYearId, tODS_GLBalance.FiscalMonthOfYearId, tods_GLMetadata.Metric

Maybe you are looking for