Subquery  and case when

hi
i have the following script
if run the subquery individually it rgives me result
but when try to run the whiole query i get error
at line as from kyword not found where expected
the query is
SELECT
Q2.BRANCH,
Q2.NAMETITLE,
Q2.PRD,
Q2.LONGNAME,
Q2.BALANCE1,
Q2.BALANCE2,
Q2.BALANCE3,
Q2.BALANCE4,
Q2.BALANCE5,
Q1.REMARK
FROM
SELECT
PRDACCTID PRD,
LBRCODE BRANCH,
case
when
     (prdacctid,lbrcode) in 
          select prdacctid,lbrcode from d010053
                 where (lbrcode,prdacctid)
          in (
               select lbrcode,prdacctid from d009022 where acctstat<>3
               and (lbrcode,trim(substr(prdacctid,1,8))) in
                    (select lbrcode,trim(prdcd) from d009021 where moduletype in (10,11,12))
     and nametype=1
then
     'yes'
else
     'no'
end
) as remark
FROM D009022
WHERE ACTSTAT<>3
AND TRIM(SUBSTR(PRDACCTID,1,8)) IN ('SB','CD','CC')
   )Q1,
          SELECT
          BRANCH,
          NAMETITLE,
          PRD,
          LONGNAME,
          BALANCE1,
          BALANCE2,
          BALANCE3,
          BALANCE4,
          BALANCE5,
          FROM
                    SELECT A.*,B.* ,
                    A.PRDACCTID PRD,
                    A.LBRCODE BRANCH,
                    RANK() OVER(PARTITION BY B.LBRCODE,B.PRDACCTID ORDER BY B.CBLDATE DESC) AS RNK
                    FROM D009022 A,D010014 B
                    WHERE A.LBRCODE=B.LBRCODE
                    AND A.PRDACCTID=B.PRDACCTID
                    AND CBLDATE<'01-APR-09'
                    AND A.ACCTSTAT!=3
                    AND (TRIM(SUBSTR(A.PRDACCTID,1,8)),A.LBRCODE) IN
                    (SELECT TRIM(PRDCD),LBRCODE FROM D009021 WHERE MODULETYPE IN (10,11,12,13,14,30))
               WHERE RNK=1
   )Q2
WHERE Q1.BRANCH=Q2.BRANCH
AND Q1.PRD=Q2.PRD
/

If you formatted your query better, then you might have spotted the issue yourself...
In your Q2 query, you've got "BALANCE5 *,* FROM ..." so remove the extra comma, like so:
SELECT Q2.BRANCH,
       Q2.NAMETITLE,
       Q2.PRD,
       Q2.LONGNAME,
       Q2.BALANCE1,
       Q2.BALANCE2,
       Q2.BALANCE3,
       Q2.BALANCE4,
       Q2.BALANCE5,
       Q1.REMARK
FROM  (SELECT PRDACCTID PRD,
              LBRCODE BRANCH,
              case when (prdacctid,lbrcode) in (select prdacctid,lbrcode
                                                from   d010053
                                                where  (lbrcode,prdacctid) in (select lbrcode,prdacctid
                                                                               from   d009022
                                                                               where  acctstat != 3
                                                                               and    (lbrcode,trim(substr(prdacctid,1,8))) in (select lbrcode,trim(prdcd)
                                                                                                                                from   d009021
                                                                                                                                where  moduletype in (10,11,12)))
                                                and    nametype=1)
                         then 'yes'
                   else 'no'
              end as remark
       FROM   D009022
       WHERE  ACTSTAT != 3
       AND    TRIM(SUBSTR(PRDACCTID,1,8)) IN ('SB','CD','CC')) Q1,
      (SELECT BRANCH,
              NAMETITLE,
              PRD,
              LONGNAME,
              BALANCE1,
              BALANCE2,
              BALANCE3,
              BALANCE4,
              BALANCE5    -- removed extra comma from here
       FROM   (SELECT A.*,B.* ,
                      A.PRDACCTID PRD,
                      A.LBRCODE BRANCH,
                      RANK() OVER(PARTITION BY B.LBRCODE,B.PRDACCTID ORDER BY B.CBLDATE DESC) AS RNK
               FROM   D009022 A,D010014 B
               WHERE  A.LBRCODE=B.LBRCODE
               AND    A.PRDACCTID=B.PRDACCTID
               AND    CBLDATE < to_date('01/04/2009', 'dd/mm/yyyy')
               AND    A.ACCTSTAT != 3
               AND    (TRIM(SUBSTR(A.PRDACCTID,1,8)),A.LBRCODE) IN (SELECT TRIM(PRDCD),LBRCODE
                                                                    FROM   D009021
                                                                    WHERE  MODULETYPE IN (10,11,12,13,14,30)))
       WHERE  RNK=1) Q2
WHERE  Q1.BRANCH = Q2.BRANCH
AND    Q1.PRD = Q2.PRDEdited by: Boneist on 06-Aug-2009 10:20
Added in the to_date around the date which I forgot to point out earlier (but BluShadow has already done so!)
Also added in a comment on the line I removed the extra comma from.

Similar Messages

  • Combine greatest, sum, and case when

    All,
    I have the following view
    Select table1.field1,
    greatest(sum(table1.field3) - case when table1.oneorzerocolumn=1 then table1.field2 else table1.field4 end,0) as NetAbove0
    from table1
    group by table1.field1;
    I seem to be having trouble figuring out the best way to accomplish this, though, as whenever I try to execute this query I get not a valid group by expression. How can I combine the greatest function and the aggregate sum function without creating a separate view?
    Thanks in advance.
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE     11.2.0.2.0     Production
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    Edited by: 929933 on Mar 14, 2013 1:32 PM

    929933 wrote:
    @ sb92075 would you care to elaborate on exactly what was missing?If you would care to read the link sb92075 posted you will understand by yourself:
    What is particularly important in that FAQ is:
    6) Tables/Indexes
    7) Sample Data
    8) Expected Output
    9) Formatting with {noformat}{noformat} Tags
    You have posted an unformatted code and did not provide proper input.
    Coming to your problem the issue is quite clear. If you use a GROUP BY clause then all field which are not returned as aggregated function shall be included in the GROUP BY clause.
    And this has a logic.
    Your initial query (formatted in a decent way):SELECT table1.field1
    , GREATEST (SUM (table1.field3)
    - CASE
    WHEN table1.oneorzerocolumn = 1 THEN
    table1.field2
    ELSE table1.field4
    END, 0) AS netabove0
    FROM table1
    GROUP BY table1.field1;
    is not correct.
    The column used in the query table1.oneorzerocolumn, table1.field2 and table1.field4 are not part of the GROUP BY and not used in aggregation functions.
    So how could you determine the value, i.e. table1.oneorzerocolumn, if for the same value of table1.field1 you have different values of table1.oneorzerocolumn?
    You are aggregating by field1 so which value do you want to use for non aggregated columns?
    Everything will be easier to understand if you can post some sample data, explain the logic you want to apply and post the expected output for the sample data you have posted.
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Pro C syntax and CASE WHEN

    Hi
    I'm developping an application using Pro C* in a C program. I have a problem, I would like to use a CASE WHEN statement inside a SELECT statement. I try the following code with compilation error:
    EXEC SQL PREPARE pr_avor_annul FROM
    INSERT INTO avor (NO_AVOR,MT_TOTL_AVOR,CD_DEVS,AC_STAT_AVOR,NO_FACT,MT_FRAS,
    MT_ARTC,AC_AVOR,NO_COMP,MT_FRAS_CONT_REMB,DT_AVOR)
    SELECT :vavor, mt_totl_fact + cout_livr + nvl(mt_fras_cont_remb,0), cd_devs,:vemis ,no_fact,cout_livr , mt_totl_fact, :vacavor, :vcomp, mt_fras_cont_remb,DECODE( (SELECT 0 FROM fact WHERE TO_CHAR(dt_fact)<TO_CHAR(sysdate)
    AND no_fact= :vfact),dt_fact, sysdate, dt_fact)
    FROM fact
    WHERE no_fact = :vfact;
    This code seems to be wrong but I don't know where...
    Somebody can help me??
    Thans a lot

    Hi,
    I'm not clear on the distinction you're making for type of access.
    Well, to be honest, now that I've re-read that this morning I'm not completely sure what I had in mind either. I think I was thinking about using the collection in what I believe the documentation calls "slices". However, given the other information you've posted it doesn't seem like that would be a feasible alternative in any case.
    I understand what you mean about varray and nested-table with the upper-bound limit for the varray's... I've not actually compared the two for performance so my idea that there may be a difference could be completely incorrect. Beyond that, creating code that only works in batches (or slices) may be less performant than what you currently have.
    I hope I've not detracted from the thread and maybe someone else with more experience will have an "ah ha!" sort of observation.
    Regards,
    Mark

  • How to use case when statements in ODI

    I need to put conditional logic before DVM look up in ODI. In the expression editor I put the following statement:-
    CASE WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='RCS' THEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME=EBIZ_CELL.CELL_DATA
    WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='FDC' THEN CONCAT(POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME,POC_JOURNAL_TEMP_SOURCE_TBL.BOOK_CODE)=EBIZ_CELL.CELL_DATA
    END
    It did not work,
    Under Operators ->All Executions, found the error:-
    905 : 42000 : java.sql.SQLException: ORA-00905: missing keyword
    The description in Session Task contained:-
    select     
         C1_JOURNAL_TEMPL
    from     APPS.POC_JOURNAL_TEMP_SOURCE_TBL POC_JOURNAL_TEMP_SOURCE_TBL, APPS.C$_0POC_JOURNAL_TEMP_TARGET_TB
    where     
         (1=1)
    And (CASE
    WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='RCS'
    THEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME=C2_CELL_DATA
    WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='FDC'
    THEN CONCAT(POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME,POC_JOURNAL_TEMP_SOURCE_TBL.BOOK_CODE)=C2_CELL_DATA
    END)
    Checked the above code in PL/SQL Developer but it gave errors.
    In PL/SQL developer tried to check a simple query using case-when but even that is giving errors in the case-when portion.
    The query is as follows:-
    select phase_code, accounting_period, sum(eff_cc) as BD_Eff_QTD
    from prj_detail
    where
    case POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME
    when 'EXT'
    then
    1
    when 'RAC'
    then
    2
    when 'XXX'
    then
    3
    else
    end
    I would like to know what is wrong with the above code.
    Please let me know what is the correct way of using case-when in PL/SQL as well as in ODI.

    Your ODI case statement and PL/SQL Case statement both looks confusing.
    You are writing case statement under where clause which is not a good practise. If you want to implement logic like-
    select a,b,c from <table>
    where
    when cond^n^ 1 then do 1
    when cond^n^ 2 then do 2
    then better you seperate your query for each filter and do a union, in other words-
    select a,b,c from <table>
    where cond^n^ 1
    union
    select a,b,c from <table>
    where cond^n^ 2
    If you are writing case staement to retrieve a value/column (EBIZ_CELL.CELL_DATA) then no need to include it under filter.
    ODI case for column EBIZ_CELL.CELL_DATA will be:
    CASE
    WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='RCS'
    THEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME
    WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='FDC'
    THEN CONCAT(POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME,POC_JOURNAL_TEMP_SOURCE_TBL.BOOK_CODE)
    END
    Pl/SQL query-
    select phase_code, accounting_period,
    case POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME
    when 'EXT'then 1
    when 'RAC' then 2
    when 'XXX' then 3
    else 'default value' --- (if no else needed then can also remove else part)
    end,
    sum(eff_cc) as BD_Eff_QTD
    from prj_detail
    Suggested as per what is understood, hope it helps.
    Edited by: 939451 on Jul 5, 2012 12:47 AM
    Edited by: 939451 on Jul 5, 2012 12:48 AM

  • Using more than one case when statement

    Hi there,
    I have a question on using case when statements.
    Currently I have a table where it shows me mulitple dates.
    Order Saledate TransferDate StartDate Enddate GetDate
    I have created a where statement to show me records against the transferdate dependant if it appears within the date range of the year, or if it appears within the startdate and today's date.
    (lpatran.trandate between targets.startdate
    and (case when targets.enddate < getdate() then targets.enddate else getdate() end))
    However on some of the records the transfer date is null, and so they want to use the saledate as the date to use.
    So I created
    (case when Lpatran.trandate is not null then (Lpatran.trandate between targets.startdate
    and (case when targets.enddate < getdate() then targets.enddate else getdate()))
    else (lpatran.saledate between targets.startdate
    and (case when targets.enddate < getdate() then targets.enddate else getdate())) end )
    However it gives me an incorrect syntax near the word ‘between ‘ 
    Is there a simple fix for this or does sql not allow me to do this?

    I have created a new column called transferdate and done a case when statement
    CASE
    WHEN lpatran.trandate
    IS
    NULL
    THEN lpatran.saledate
    ELSE lpatran.trandate
    END
    AS Transferdate,
    Then created a temptable and did a select * from temptable.  Created a where statement from transferdate, which does work and gives me the correct data. 
    TransferDate between startdate
    and(case
    when enddate
    <
    getdate()
    then enddate
    else
    getdate()
    end))
    However I wanted to know if there was a way of obtaining the same data without having to use the temptable ?

  • Returne between dates in case when

    i want to return between dates values on case when clauses on where clauses
    like
    and
    (case
    when (cc.segment3 NOT like '4%' and cc.segment3 NOT like '5%')
    then (between to_date('01/07/2012','dd/mm/rrrr') and to_date('31/07/2012','dd/mm/rrrr'))
    when (cc.segment3 like '4%' or cc.segment3 like '5%')
    then (between to_date('01/07/2012','dd/mm/rrrr') and to_date('31/07/2012','dd/mm/rrrr'))
    end) h.default_effective_date
    the problem is in the = operator but i don't know haw to use this
    any help??

    ok here is the full coad
    select
    DECODE(SUBSTR (CC.segment1, 1, 1), 'J', 'OFFSHORE', 'I', 'OFFSHORE','IN COUNTRY')branch_nature,
    decode(cc.segment1,'A6260','Head Office','Branches') branch_type,
    cc.segment1,
    decode (h.currency_code,'EGP','mahly','agnaby') currency_code ,
    cc.segment3,
    t.description,
    CASE
    when h.currency_code in('EGP') then sum(l.entered_cr)
    else 0
    end entered_cr,--sum(l.entered_cr) entered_cr,
    CASE
    when h.currency_code in('EGP') then sum(l.entered_dr)
    else 0
    end entered_dr, --sum(l.entered_dr) entered_dr,
    CASE
    when h.currency_code NOT in('EGP') then sum(l.accounted_cr)
    else 0
    end accounted_Dr,--0 accounted_Dr,
    CASE
    when h.currency_code NOT in('EGP') then sum(l.accounted_dr)
    else 0
    end accounted_cr --0 accounted_cr
    from apps.gl_je_headers h,
    apps.gl_je_lines L,
    apps.gl_code_combinations cc,
    apps.fnd_flex_values_tl t ,
    applsys.fnd_user us,
    apps.gl_je_batches b
    where h.status = 'P'
    and us.user_id = h.Created_by
    --and h.currency_code in('EGP')
    and l.je_header_id = h.je_header_id
    and l.code_combination_id =cc.code_combination_id
    and cc.segment3 = t.flex_value_meaning
    and cc.segment3 in ('31000020','40505020')
    and cc.segment1 in ('A5550','B0010')
    -- and (DECODE(SUBSTR (CC.segment1, 1, 1), 'J', 'OFFSHORE', 'I', 'OFFSHORE','IN COUNTRY') =:P_branch_nature OR :P_branch_nature is NULL)
    --and (decode(cc.segment1,'A6260','Head Office','Branches') = :P_BRANCH_TYPE OR :P_BRANCH_TYPE is NULL)
    and t.description is not null
    and t.language ='AR'
    and h.je_batch_id = b.je_batch_id
    and
    (case
    when (cc.segment3 NOT like '4%' and cc.segment3 NOT like '5%')
    then (between to_date(:P_Start_date,'dd/mm/rrrr') and to_date(:P_END_date,'dd/mm/rrrr'))
    when (cc.segment3 like '4%' or cc.segment3 like '5%')
    then (between to_date(:P_Start_date2,'dd/mm/rrrr') and to_date(:P_END_date,'dd/mm/rrrr'))
    end) h.default_effective_date
    and (case
    when (cc.segment3 like '4%' or cc.segment3 like '5%')
    then (h.default_effective_date)
    end) between to_date('01/07/2012','dd/mm/rrrr') and to_date('31/07/2012','dd/mm/rrrr')*/
    group by cc.segment3 , t.description , cc.segment1,h.currency_code;
    the part between tages need to modigied

  • Error in case when

    hi friends
        i have below query which is throwing error  'missing expression' which is on bold.
        please correct the query.
       SELECT max(lv.lv_lastupdate)  INTO v_old_date FROM loanable_value lv
       WHERE lv.lv_rm_cust_id= p_gfcid AND lv.lv_year= p_year
       AND  (CASE  WHEN     p_Quarter ='Q1'  THEN    lv.lv_month IN ('Jan','Feb','Mar')  END ) ;

    RajnishChauhan wrote:
    hi friends
        i have below query which is throwing error  'missing expression' which is on bold.
        please correct the query.
       SELECT max(lv.lv_lastupdate)  INTO v_old_date FROM loanable_value lv
       WHERE lv.lv_rm_cust_id= p_gfcid AND lv.lv_year= p_year
       AND  (CASE  WHEN     p_Quarter ='Q1'  THEN    lv.lv_month IN ('Jan','Feb','Mar')  END ) ;
    How do you expect us to correct it if we don't know what you want?
    However, I'm guessing you want
    and (
    (p_quarter = 'Q1' and lv.lv_month in ('Jan','Feb','Mar'))
    or (p_quarter = 'Q2' and lv.lv_month in ('Apr','May','Jul'))
    or..
    difficulties you could have avoided if you'd not split things up as lv_year,lv_month etc. and just kept the field as a single DATE.
    Then it would be a simple as
    where to_char(lv.lv_date,'Q')=p_quarter
    where p_quarter is 1,2,3 or 4

  • 2008R2 - cumulative based on count and additional subquery where CASE SUM

    Hi;
    I have two queries where I'm struggling to get a cumulative and sum due to use of counts in the initial query;
    First up cumulative where I suspect a cursor will be required.
    SELECT TOP (100) PERCENT DATEPART(week, time_stamp) AS Week, COUNT(DISTINCT [user]) AS UnqCnt
    FROM dbo.vw_ctrx_archive_ica_roundtrip_perf
    WHERE (time_stamp BETWEEN GETDATE() - 120 AND GETDATE()) AND (dept_path LIKE 'All\XenApp Farms\AppName\%')
    GROUP BY DATEPART(week, time_stamp)
    ORDER BY week
    This produces a unique count of users grouped by week number, However What I want to show is a cumulative total as each week goes by;
    Week 1 100 unique users
    By end of Week 2
    220 unique users
    By end of week 3 
    250 unique users and so forth.
    In this instance this level of reporting is only required for the next 10 - 12 weeks so I'm happy to go inefficient ala in the vain of;
    SELECT TOP (100) PERCENT Week, UnqCnt,
    (SELECT SUM(UnqCnt) AS Expr1
    FROM dbo.vw_someview AS t2
    WHERE (Week <= t1.Week)) AS RunningT
    FROM dbo.vw_someview AS t1
    ORDER BY Week
    (The above isn't what I need as it simply totals each week as opposed to showing unique to date, but less complexity works for me!)
    EDIT - Examples of source data and desired output. I've trimmed down to show just the required data.
    Current input;
    Current output;
    What I actually want is a cumulative unique count by week to date, not per week.
    So the next query is based on a count of unique users plus a CASE SUM showing split between two regions (UK and US). However there is a mismatch with the unique user count total due to potential multiple records existing for a user which is included in the
    CASE SUMs. Again I know a subquery is necessary but I'm struggling to work it in conjunction with the CASE SUMS.
    SELECT        TOP (100) PERCENT time_stamp, CONVERT(varchar(2), DATEADD(day, 0, time_stamp), 105) + '-' + CONVERT(varchar(2), DATEADD(hh, 0, time_stamp), 108) 
                             + ':00' AS Time, COUNT(DISTINCT [user]) AS Combined, 
                             SUM(CASE WHEN dbo.vw_ctrx_archive_session_perf.dept_path LIKE 'All\XenApp Farms\someservers\UK%' THEN 1 ELSE 0 END) AS UK, 
                             SUM(CASE WHEN dbo.vw_ctrx_archive_session_perf.dept_path LIKE 'All\XenApp Farms\someservers\US%' THEN 1 ELSE 0 END) AS US
    FROM            dbo.vw_ctrx_archive_session_perf
    WHERE        (dept_path LIKE 'All\XenApp Farms\someservers\%')
    GROUP BY time_stamp, CONVERT(varchar(2), DATEADD(hh, 0, time_stamp), 108)
    ORDER BY time_stamp
    EDIT - Examples of source data and desired output. I've trimmed down to show just the required data.
    Current input;
    Current output;
    As you can see the mismatch between Combined and region due to no logic with the CASE SUMS to only perform that SUM for a unique user.
    Any help or pointers for either question would be very much appreciated.
    Thanks, Paul.

    The first query the cte returns one row for each customer who has a order into the @MinWeekCounts table variable.  With that customer id, the cte returns the first week that customer has an order.  So if customer number 1 has two orders in week
    3, 5 orders in week 7 and one order in week 9, the cte will return one row for customer number 1 with the week set to 3.
    Then the result of the cte (one row for each customer with the week that customer first had an order) is grouped by week and we get a count of the customers for that week.  So now we have for each week the count of the customers whose first order was
    in that week.  So for week 1 we have the count of the customers who ordered in week 1.  For week 2, we have the count of the customers who ordered in week 2, but did not order in week 1.  For week 3, we have the count of the customers who ordered
    in week 3, but did not order in either week 1 or week 2.  The query then inserts that result into the @MinWeeksCounts table variable.
    So now we have a count for each week of the number of customers whose first order was in that week.  So the result we want is just the running total of those counts.  For example, for week three, you want the number of customers who ordered ordered
    in week 3 or earlier.  That's just the number of customers who first ordered in week 1 + the number of customers who first ordered in week 2 plus the number of customers who first ordered in week 3.  So the running total for each week will give
    you the result you want.  So we write the final query to give you the result by doing a running total of each week's count of the customers who first ordered in each week.
    Tom

  • Case When Statement and ORA:01722 Invalid number error

    Hi folks, I have posted this under another heading as well under E-business suite so apologies if some you have already seen it but I would really appreciate some help on this one. Any suggestions are most welcome.
    We are trying to put together a calculation that returns the number of days absent an individual has had in a given time period. We need to cater for those absences that started before the period and are closed during it, absence that start during the period and end after it, and those that open and close within it.
    The period is always a rolling 6 months from sysdate.
    This is the calc we have come up with so far which works for some people but we get the invalid number error if the absence includes a half day - so 0.5, 1.5,etc.
    This is probably over complicated but we are not techie at all so are learning as we go!
    We are using the HRMS - Administration - Oracle Human Resources (Core) business area in 10G and the Absence Attendance and Person folders.
    SUM(TO_NUMBER(NVL(( CASE WHEN Absence Attendance.Actual Start Date < TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY') THEN ( CASE WHEN Absence Attendance."Actual End Date" > SYSDATE THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),SYSDATE) ) ELSE ( CASE WHEN ( CASE WHEN TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY') >= Absence Attendance.Actual Start Date THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),Absence Attendance."Actual End Date") ) ELSE ( CASE WHEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) IS NULL THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( CASE WHEN SYSDATE <= Absence Attendance."Actual End Date" THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) END ) END ) END ) IS NULL THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),SYSDATE) ) ELSE ( CASE WHEN TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY') >= Absence Attendance.Actual Start Date THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),Absence Attendance."Actual End Date") ) ELSE ( CASE WHEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) IS NULL THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( CASE WHEN SYSDATE <= Absence Attendance."Actual End Date" THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) END ) END ) END ) END ) END ) ELSE ( CASE WHEN ( CASE WHEN TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY') >= Absence Attendance.Actual Start Date THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),Absence Attendance."Actual End Date") ) ELSE ( CASE WHEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) IS NULL THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( CASE WHEN SYSDATE <= Absence Attendance."Actual End Date" THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) END ) END ) END ) IS NULL THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),SYSDATE) ) ELSE ( CASE WHEN TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY') >= Absence Attendance.Actual Start Date THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),Absence Attendance."Actual End Date") ) ELSE ( CASE WHEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) IS NULL THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( CASE WHEN SYSDATE <= Absence Attendance."Actual End Date" THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( Absence Attendance.Duration Days ) END ) END ) END ) END ) END ),( DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") )),'999999990D00'))

    Hi,
    It could be that this is because you are using SYSDATE which contains the time as a fraction rather than TRUNC(SYSDATE) which just contains the current time. It could be that your working_dates_between raises this error.
    However, your formula is far more complicated than it needs to be.
    Firstly, you want to look at the date window ADD_MONTHS(TRUNC(SYSDATE), -6) to TRUNC(SYSDATE). Then you want to look at the portion of the absence that falls in the date window. This is GREATEST(Absence Attendance.Actual Start Date, ADD_MONTHS(TRUNC(SYSDATE), -6)) to LEAST(NVL(Absence Attendance."Actual End Date",TRUNC(SYSDATE)), TRUNC(SYSDATE)). You may need to add 1 to the absence end date because this is the last day of their absence rather than the date they return. It depends how you calculate the days between the start and end
    date of the absence. You can create calculations for the start and end date of the absences within the 6 months time window. Create calculation AbsenceStart as
    GREATEST(Absence Attendance.Actual Start Date, ADD_MONTHS(TRUNC(SYSDATE), -6))
    and AbsenceEnd as
    LEAST(NVL(Absence Attendance."Actual End Date",TRUNC(SYSDATE)), TRUNC(SYSDATE))
    Then you need to only pick up absence that a part of the absence in your 6 month date window. You can use a condition in the workbook or a condition in a case statement to do this. You then need to calculate the difference between these dates and SUM all the values.
    SUM(CASE WHEN AbsenceEnd >= AbsenceStart THEN WORKING_DAYS_BETWEEN(AbsenceStart, AbsenceEnd) END)
    That's it. Not so complicated after all.
    Rod West

  • Case When Statement and ORA:1722 Invalid number error

    Sorry I posted this in the wrong forum - I have the answer now
    Cheers
    HELP!!!
    We are trying to put together a calculation that returns the number of days absent an individual has had in a given time period. We need to cater for those absences that started before the period and are closed during it, absence that start during the period and end after it, and those that open and close within it.
    The period is always a rolling 6 months from sysdate.
    This is the calc we have come up with so far which works for some people but we get the invalid number error if the absence includes a half day - so 0.5, 1.5,etc.
    This is probably over complicated but we are not Techie at all so are learning as we go! We are using the HRMS - Administration - Oracle Human Resources (Core) business area in 10G and the Absence Attendance and Person folders.
    SUM(TO_NUMBER(NVL(( CASE WHEN Absence Attendance.Actual Start Date < TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY') THEN ( CASE WHEN Absence Attendance."Actual End Date" > SYSDATE THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),SYSDATE) ) ELSE ( CASE WHEN ( CASE WHEN TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY') >= Absence Attendance.Actual Start Date THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),Absence Attendance."Actual End Date") ) ELSE ( CASE WHEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) IS NULL THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( CASE WHEN SYSDATE <= Absence Attendance."Actual End Date" THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) END ) END ) END ) IS NULL THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),SYSDATE) ) ELSE ( CASE WHEN TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY') >= Absence Attendance.Actual Start Date THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),Absence Attendance."Actual End Date") ) ELSE ( CASE WHEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) IS NULL THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( CASE WHEN SYSDATE <= Absence Attendance."Actual End Date" THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) END ) END ) END ) END ) END ) ELSE ( CASE WHEN ( CASE WHEN TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY') >= Absence Attendance.Actual Start Date THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),Absence Attendance."Actual End Date") ) ELSE ( CASE WHEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) IS NULL THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( CASE WHEN SYSDATE <= Absence Attendance."Actual End Date" THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) END ) END ) END ) IS NULL THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),SYSDATE) ) ELSE ( CASE WHEN TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY') >= Absence Attendance.Actual Start Date THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),Absence Attendance."Actual End Date") ) ELSE ( CASE WHEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) IS NULL THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( CASE WHEN SYSDATE <= Absence Attendance."Actual End Date" THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( Absence Attendance.Duration Days ) END ) END ) END ) END ) END ),( DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") )),'999999990D00'))
    Edited by: CPearce on Sep 25, 2008 8:03 AM

    Hi,
    It could be that this is because you are using SYSDATE which contains the time as a fraction rather than TRUNC(SYSDATE) which just contains the current time. It could be that your working_dates_between raises this error.
    However, your formula is far more complicated than it needs to be.
    Firstly, you want to look at the date window ADD_MONTHS(TRUNC(SYSDATE), -6) to TRUNC(SYSDATE). Then you want to look at the portion of the absence that falls in the date window. This is GREATEST(Absence Attendance.Actual Start Date, ADD_MONTHS(TRUNC(SYSDATE), -6)) to LEAST(NVL(Absence Attendance."Actual End Date",TRUNC(SYSDATE)), TRUNC(SYSDATE)). You may need to add 1 to the absence end date because this is the last day of their absence rather than the date they return. It depends how you calculate the days between the start and end
    date of the absence. You can create calculations for the start and end date of the absences within the 6 months time window. Create calculation AbsenceStart as
    GREATEST(Absence Attendance.Actual Start Date, ADD_MONTHS(TRUNC(SYSDATE), -6))
    and AbsenceEnd as
    LEAST(NVL(Absence Attendance."Actual End Date",TRUNC(SYSDATE)), TRUNC(SYSDATE))
    Then you need to only pick up absence that a part of the absence in your 6 month date window. You can use a condition in the workbook or a condition in a case statement to do this. You then need to calculate the difference between these dates and SUM all the values.
    SUM(CASE WHEN AbsenceEnd >= AbsenceStart THEN WORKING_DAYS_BETWEEN(AbsenceStart, AbsenceEnd) END)
    That's it. Not so complicated after all.
    Rod West

  • Difference of sql query in SQL Workshop and SQL Report (case when sum(...

    Hi ,
    I need some help, pls.
    The follwg report runs in SQL Workshop - but gives errors in the sql-query report in HTMLDB:
    SQL-Workshop:
    select
    case
    when SUM(S.POTENTIAL_GROWTH)> 1 and SUM(S.POTENTIAL_GROWTH) < 4 then 'Ok'
    when SUM(S.POTENTIAL_GROWTH)> 4 and SUM(S.POTENTIAL_GROWTH) < 8 then 'SoSo'
    when SUM(S.POTENTIAL_GROWTH)> 8 and SUM(S.POTENTIAL_GROWTH) < 12 then 'Very Good'
    else 'too much'
    end
    from "SEGMENTATION" S
    In an HTMLDB SQL-Query Report I added Aliases (as requested for HTML) but still gives the error:
    <<Query cannot be parsed, please check the syntax of your query. (ORA-00920: invalid relational operator) >>
    the code:
    select
    case
    when SUM(S.POTENTIAL_GROWTH) pot_growth > 1 and SUM(S.POTENTIAL_GROWTH)pot_growth < 4 then 'Ok'
    when SUM(S.POTENTIAL_GROWTH)pot_growth > 4 and SUM(S.POTENTIAL_GROWTH)pot_growth < 8 then 'SoSo'
    when SUM(S.POTENTIAL_GROWTH)pot_growth > 8 and SUM(S.POTENTIAL_GROWTH)pot_growth < 12 then 'Very Good'
    else 'too much'
    end
    from "SEGMENTATION" S
    any halp from the gurus wud be very much appreciated.
    TIA
    Bernhard

    Still you did not give the alias for the case when column. For that only you should give the alias
    select
    case
    when SUM(S.POTENTIAL_GROWTH) pot_growth &gt; 1 and SUM(S.POTENTIAL_GROWTH)pot_growth &lt; 4 then 'Ok'
    when SUM(S.POTENTIAL_GROWTH)pot_growth &gt; 4 and SUM(S.POTENTIAL_GROWTH)pot_growth &lt; 8 then 'SoSo'
    when SUM(S.POTENTIAL_GROWTH)pot_growth &gt; 8 and SUM(S.POTENTIAL_GROWTH)pot_growth &lt; 12 then 'Very Good'
    else 'too much'
    end "GROWTH"
    from "SEGMENTATION" S

  • Lick on the icon in appstore which allows to gift an app or copy link , post to facebook etc does not open it stucks.Also same case for itunes and moreover when I play music in iTunes it

    Itunes and appstore problems:
    i have an iPhone 5 whenever I try to click on the icon in appstore which allows to gift an app or copy link , post to facebook etc does not open it stucks.Also same case for itunes and moreover when I play music in iTunes it stops ..start again stops and start again ..stops and does not play..so I  am unable to make gift purchase and listen to the songs..are these bugs or what? help

    ps when syncing it jumps through steps 1 - 4 real fast, i seem to remeber iphone showing the number of tracks transferring and names, but i see nothing? then it sits on 5 saying "waiting for changes to be applied"

  • I have Prem. Elements 12.  I am trying to add audio media.  I know where the audio files are located (using GET INFO while in iTunes), and when I try to add certain audio files, some are accepted and some are not.  In one case, when I opened a particular

    I have Prem. Elements 12.  I am trying to add audio media.  I know where the audio files are located (using GET INFO while in iTunes), and when I try to add certain audio files, some are accepted and some are not.  In one case, when I opened a particular folder, the song was not listed, even tho' the song is there when using Windows Explorer.  This happens with mp3 and mp4 and just wav files.  Some audio are accepted, most are not.  I get that codec is not installed error message, too.

    Perhaps it would be helpful for you to view the page source code of this page
    http://www.alanwork.com/
    As you can see, the submenu code links are immediately below the top level code, and are
    wrapped in their own  <UL> </UL> tag pairs.
    Hope that helps

  • About case when and the sql clause

    Hi:
    The following is my sql clause:
    SELECT t.*,b.name
    FROM dbtest1 t
    LEFT OUTER JOIN dbtest b ON t.NO = b.empno
    WHERE t.ChineseName like '%'||:ChineseName||'%' AND b.name like '%'||:name||'%'
    ORDER BY t.ChineseName
    The main problem is I hope to check the b.name if it is null it can be passed as NVL function, so I try using case when, but it not working.
    When b.name exist in where clause, the result columns will not include the data without b.name(or implies the b.name is NULL); And that
    make the result data not exactly right.
    is it possible to use case when to make the following snippet implemented:
    case when b.name is not NULL then b.name like '%'||:name||'%'
    else b.name = NULL(b.name=b.name seems not work to parsing null data)
    end
    Thanks a lot.

    962769 wrote:
    Hi:
    The following is my sql clause:
    SELECT t.*,b.name
    FROM dbtest1 t
    LEFT OUTER JOIN dbtest b ON t.NO = b.empno
    WHERE t.ChineseName like '%'||:ChineseName||'%' AND b.name like '%'||:name||'%'
    ORDER BY t.ChineseName
    The main problem is I hope to check the b.name if it is null it can be passed as NVL function, so I try using case when, but it not working.
    When b.name exist in where clause, the result columns will not include the data without b.name(or implies the b.name is NULL); And that
    make the result data not exactly right.
    is it possible to use case when to make the following snippet implemented:
    case when b.name is not NULL then b.name like '%'||:name||'%'
    else b.name = NULL(b.name=b.name seems not work to parsing null data)
    end
    Thanks a lot.Your question isn't very clear. But below is the statement as I make a meaning out of it.
    SELECT t.*,b.name
    FROM dbtest1 t
    LEFT OUTER JOIN dbtest b ON t.NO = b.empno
    WHERE t.ChineseName like '%'||:ChineseName||'%'
         AND b.name like '%'||NVL(:name, b.name)||'%'
    ORDER BY t.ChineseNameIf you want to use case, then:
    SELECT t.*,b.name
    FROM dbtest1 t
    LEFT OUTER JOIN dbtest b ON t.NO = b.empno
    WHERE t.ChineseName like '%'||:ChineseName||'%'
         AND b.name like '%'|| case when b.name is not null then :name else b.name end ||'%'
    ORDER BY t.ChineseNameIf this is not what you are looking for then, read {message:id=9360002} and post the relevant details with an example (Create Table script, Sample Data creation script and the Expected output of the sample data).

  • Subqueries and Case

    I have two codes - A & B
    My question is can I use code B i.e Case statement as a subquery of code A to get the necessary output
    =============================CODE A=====================================================
    select a.search_code,a.name,a.total as "Total Service Calls",decode(b.total_adjusted_miss,null,0,b.total_adjusted_miss) "Missed SLA (Adjusted)",
    decode(c.total_unadjusted_miss,null,0,c.total_unadjusted_miss) "Missed SLA (UnAdjusted)",
    decode(round(((a.total - b.total_adjusted_miss)/a.total)*100,2),null,100,round(((a.total - b.total_adjusted_miss)/a.total)*100,2)) "Total Adjusted Yield %",
    decode(round(((a.total - c.total_unadjusted_miss)/a.total)*100,2),null,100,round(((a.total - c.total_unadjusted_miss)/a.total)*100,2)) "Total UnAdjusted Yield %"
    from (
    (SELECT
    count(*) as total,
    sg.search_code,
    sg.NAME
    FROM
    task t,
    operational_process op,
    support_group sg,
    person p
    where sg.support_group_seq_id in (SELECT sg2.support_group_seq_id FROM support_group sg2
    start with sg2.SEARCH_CODE = p_target_name
    connect by prior sg2.support_group_seq_id=sg2.parent_support_group_seq_id)
    and t.task_seq_id = op.task_seq_id
    and t.task_seq_id = op.task_seq_id
    and sg.support_group_seq_id = op.support_group_seq_id
    and op.assigned_person_seq_id = p.person_seq_id
    and sg.search_code = p_target_name
    and t.task_type in ('Inc')
    and to_char(op.est_actual_end_datetime, 'MM-YYYY') = '02-2012'
    and t.priority is not null
    group by sg.search_code, sg.name
    ))a,
    =============================CODE B=====================================================
    Select t.task_number, CASE
    WHEN ((T.PRIORITY like ('%Immediate%')) AND
    (OP._ACTUAL_END_DATETIME - OP._ACTUAL_START_DATETIME) * 24 < 2) THEN
    1
    WHEN ((T.PRIORITY like ('%Critical%')) AND
    (OP._ACTUAL_END_DATETIME - OP._ACTUAL_START_DATETIME) * 24 < 4) THEN
    1
    WHEN ((T.PRIORITY like ('%Urgent%')) AND
    OP.ACTUAL_DUR_HOURS_DECIMAL <= 24) THEN
    1
    WHEN ((OP.PRIORITY like ('%Medium%')) AND
    OP.ACTUAL_DUR_HOURS_DECIMAL <= 120) THEN
    1
    WHEN ((T.PRIORITY like ('%Normal%')) AND
    OP.ACTUAL_DUR_HOURS_DECIMAL <= 72) THEN
    1
    ELSE
    0
    END W2W_SLA,
    CASE
    WHEN ((T.PRIORITY like ('%Immediate%')) AND
    ((OP._ACTUAL_END_DATETIME - OP._ACTUAL_START_DATETIME) * 24) -
    NVL(OP.EXCEPTION_DUR_HOURS_DEC, 0) <= 2) THEN
    1
    WHEN ((T.PRIORITY like ('%Critical%')) AND
    ((OP._ACTUAL_END_DATETIME - OP._ACTUAL_START_DATETIME) * 24) -
    NVL(OP.EXCEPTION_DUR_HOURS_DEC, 0) <= 4) THEN
    1
    WHEN ((T.PRIORITY like ('%Urgent%')) AND
    OP.ACTUAL_DUR_HOURS_DECIMAL -
    NVL(OP.EXCEPTION_DUR_HOURS_DEC, 0) <= 24) THEN
    1
    WHEN ((T.PRIORITY like ('%Medium%')) AND
    OP.ACTUAL_DUR_HOURS_DECIMAL -
    NVL(OP.EXCEPTION_DUR_HOURS_DEC, 0) <= 120) THEN
    1
    WHEN ((T.PRIORITY like ('%Normal%')) AND
    OP.ACTUAL_DUR_HOURS_DECIMAL -
    NVL(OP.EXCEPTION_DUR_HOURS_DEC, 0) <= 72) THEN
    1
    ELSE
    0
    END W2W_SLA_EXCEPTION
    from task t, operationalprocess OP, support_group s
    where t.task_seq_id = op.task_seq_id
    and t.task_type in ('Inc', 'SR')
    and op.support_group_seq_id = s.support_group_seq_id
    --and s.name = 'L3 Service Management Data Warehouse Development'
    and to_char(t._actual_end_datetime, 'MM-YYYY') = '02-2012'

    Hello
    I'm not quite clear on what you're asking. You want to know if it's possible to put query A in a subquery so you can access the columns to use in query b?
    If so, a subquery wouldn't be a particularly efficient way of doing it as you would need to repeat it for each attribute. Instead you could use an inline view something like so (bear in mind I don't have your tables or data so I can't test whether this even runs!)
    SELECT t.task_number,
          CASE
              WHEN ((t.priority LIKE ('%Immediate%')) AND
                   (op._actual_end_datetime - op._actual_start_datetime) * 24 < 2) THEN
               1
              WHEN ((t.priority LIKE ('%Critical%')) AND
                   (op._actual_end_datetime - op._actual_start_datetime) * 24 < 4) THEN
               1
              WHEN ((t.priority LIKE ('%Urgent%')) AND op.actual_dur_hours_decimal <= 24) THEN
               1
              WHEN ((op.priority LIKE ('%Medium%')) AND op.actual_dur_hours_decimal <= 120) THEN
               1
              WHEN ((t.priority LIKE ('%Normal%')) AND op.actual_dur_hours_decimal <= 72) THEN
               1
              ELSE
               0
          END w2w_sla,
          CASE
              WHEN ((t.priority LIKE ('%Immediate%')) AND ((op._actual_end_datetime - op._actual_start_datetime) * 24) -
                   nvl(op.exception_dur_hours_dec, 0) <= 2) THEN
               1
              WHEN ((t.priority LIKE ('%Critical%')) AND ((op._actual_end_datetime - op._actual_start_datetime) * 24) -
                   nvl(op.exception_dur_hours_dec, 0) <= 4) THEN
               1
              WHEN ((t.priority LIKE ('%Urgent%')) AND
                   op.actual_dur_hours_decimal - nvl(op.exception_dur_hours_dec, 0) <= 24) THEN
               1
              WHEN ((t.priority LIKE ('%Medium%')) AND
                   op.actual_dur_hours_decimal - nvl(op.exception_dur_hours_dec, 0) <= 120) THEN
               1
              WHEN ((t.priority LIKE ('%Normal%')) AND
                   op.actual_dur_hours_decimal - nvl(op.exception_dur_hours_dec, 0) <= 72) THEN
               1
              ELSE
               0
          END w2w_sla_exception
    FROM   _task t,
           operational_process op,
           support_group s,
           (SELECT a.search_code,
                   a.NAME,
                   a.total AS "Total Service Calls",
                   decode(b.total_adjusted_miss, NULL, 0, b.total_adjusted_miss) "Missed SLA (Adjusted)",
                   decode(c.total_unadjusted_miss, NULL, 0, c.total_unadjusted_miss) "Missed SLA (UnAdjusted)",
                   decode(round(((a.total - b.total_adjusted_miss) / a.total) * 100, 2)
                         ,NULL
                         ,100
                         ,round(((a.total - b.total_adjusted_miss) / a.total) * 100, 2)) "Total Adjusted Yield %",
                   decode(round(((a.total - c.total_unadjusted_miss) / a.total) * 100, 2)
                         ,NULL
                         ,100
                         ,round(((a.total - c.total_unadjusted_miss) / a.total) * 100, 2)) "Total UnAdjusted Yield %"
            FROM   ((SELECT COUNT(*) AS total, sg.search_code, sg.NAME
                     FROM   task t, operational_process op, support_group sg, person p
                     WHERE  sg.support_group_seq_id IN
                            (SELECT sg2.support_group_seq_id
                             FROM   support_group sg2
                             START  WITH sg2.search_code = p_target_name
                             CONNECT BY PRIOR sg2.support_group_seq_id = sg2.parent_support_group_seq_id)
                     AND    t.task_seq_id = op.task_seq_id
                     AND    t.task_seq_id = op.task_seq_id
                     AND    sg.support_group_seq_id = op.support_group_seq_id
                     AND    op.assigned_person_seq_id = p.person_seq_id
                     AND    sg.search_code = p_target_name
                     AND    t.task_type IN ('Inc')
                     AND    to_char(op.est_actual_end_datetime, 'MM-YYYY') = '02-2012'
                     AND    t.priority IS NOT NULL
                     GROUP  BY sg.search_code, sg.NAME)) a
            ) query_a
    WHERE  t.task_seq_id = op.task_seq_id
    AND    t.task_type IN ('Inc', 'SR')
    AND    op.support_group_seq_id = s.support_group_seq_id
         --and s.name = 'L3 Service Management Data Warehouse Development'
    AND    to_char(t._actual_end_datetime, 'MM-YYYY') = '02-2012'
    AND
           query_a.search_code = s.search_code
    AND
           query_a.NAME = s.NAMEI've put the join between the two queries as being on support_group.name and support_group.search_code. If you need to join on additional columns, you would need to include them in the inline view for query a (including group by) and add them to the join.
    If that's not what you meant, maybe you could explain a bit more.
    HTH
    David

Maybe you are looking for

  • My iPod doesn't sync all my music! HELP! :(

    Hello there! I happen to be having a couple of troubles with my iPod classic lately. The last one and the most miserable one is that last night when I added three new albums on my iTunes Library and then synced my iPod to copy them on it, I noticed t

  • Select a song to play next (after current song)

    I love iTunes, but for me it's just missing one thing.... I can't (at least I don't know how) select a certain song from my playlist to play AFTER the current song is finished... If it would have that function, or a way to do this, it would be ALL I

  • Were I can get PGI data

    Dear Guru, I want to no from which table I can get the data of Pick Qty. When I go to VL02N Pick Qty, their I can find Structure : -  LIPSD Feild : -  PIKMG. But when I am searching in PIKGM I am not getting any data. So, will u help me to get the ta

  • Need help with Buttons/Events

    HI Here is what I am doing. I am creating an "operations" calendar for my workplace. So far I have been successful with creating the page, inserting links, tags, images etc..... But now I want to add an Event button - where once the button is clicked

  • IMac 24" to HP 5100 printer woes

    I just got an HP 5100 printer to replace my old faithful 4MV but cannot get the new printer to print. I simply connected the ethernet cable from the 4MV to the 5100 Jet Direct card and all seems to work normally but, when I send a page to print, noth