Case Statement Help needed [Nested]

Hi all,
I need to write a case statement my requirement is
ENC.EET.40 E_Disposition populated from either “E_ Status” field of HP_Response_table, “File Status” of HP _TTT_Response_Table,
or “E_Status” of DDA_R_Table. If no data in any of these fields, default to “Submitted”
 So my case stmt should look like
case when E_Status is null then 'SUBMITTED'
when   e_status is null then 'Submitted'
when    FileStatus is null then 'Submitted'
Else case when E_status is not null then ............?????????????
else case when
Im Confused.. Can someone help me ?
FM

select ...
coalesce (resp.E_Status, resp2.FileStatus, dda.E_Status, 'Submitted')
from ...
Obviously I have used alias for the respective tables according to your logic.

Similar Messages

  • Case Statement Help needed

    case
    when datepart(mm,[SDate]) between '9' and '11' and datepart(mm,[PDate] ) between '9' and '11'
    Then 'Q1_'
    when datepart(mm,[SDate]) between '12' and '02' and datepart(mm,[PDate] ) between '12' and '02'
    Then 'Q2_'
    when datepart(mm,[SDate]) between '03' and '05' and datepart(mm,[PDate] ) between '03' and '05'
    Then 'Q3_'
    when datepart(mm,[SDate]) between '06' and '08' and datepart(mm,[PDate] ) between '06' and '08'
    Then 'Q4_'
    else 'N/A' end as QTR
    from DDA_2015_FSR
    Datatype for SDate and Pdate
    2014-09-01 00:00:00
    I need help with above case statement, When I run the case statement I get 'N/A FSY_2015   ' When I add the following where clause to validate the results. In my table I do have records for all four quarters, Except Q1, all other rows I get  'N/A
    FSY_2015   '
    Am i missing something? Can someone help me here?
    where
    datepart(m,[SDate]) 
    between
    '12'
    and
    '02'
    and  
    datepart(m,[PDate]
    between
    '12'
    and
    '02'
    FM

    There is no CASE statement in SQL; it is a CASE expression. Big difference. 
    Since SQL is a database language, we prefer to do look ups and not calculations. They can be optimized while temporal math messes up optimization. A useful idiom is a report period calendar that everyone uses so there is no way to get disagreements in the DML.
    The report period table gives a name to a range of dates that is common to the entire enterprise. 
    CREATE TABLE Something_Report_Periods
    (something_report_name CHAR(10) NOT NULL PRIMARY KEY
       CHECK (something_report_name LIKE <pattern>),
     something_report_start_date DATE NOT NULL,
     something_report_end_date DATE NOT NULL,
      CONSTRAINT date_ordering
        CHECK (something_report_start_date <= something_report_end_date),
    etc);
    These report periods can overlap or have gaps. I like the MySQL convention of using double zeroes for months and years, That is 'yyyy-mm-00' for a month within a year and 'yyyy-00-00' for the whole year. The advantages are that it will sort with the ISO-8601
    data format required by Standard SQL and it is language independent. The pattern for validation is '[12][0-9][0-9][0-9]-00-00' and '[12][0-9][0-9][0-9]-[01][0-9]-00'
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Case statement help needed bit tricky

    I have a requirement for a Column Quarters which will idenitfy records based on their service and paid paids.
    Output of Column should be
    QTR
    FSY2015Q1
    Our Quarters start like this Q1= 9/1 /2014-11.30.2014 , Q2 12/1/2014 -02/28/2015, Q3: 3/1/2015 - 05/31/2015 Q4:06/01/2015 -08/31/2015.
    With the below Case statement  records that hit Q1 should be for the FSY upcoming.  records  in Sept, Oct, November of 2014, would actually be for FSY15Q1  (not FSY14Q1).   How can i correct
    this ?
    case
    when datepart(mm, Service_Through_Date ) between '9' and '11' and datepart(mm, c.paid_date ) between '9' and '11'
    Then 'Q1 '
    when datepart(mm, Service_Through_Date ) in ('01','02', '12' ) and datepart(mm, paid_date ) in ('01','02' , '12' )
    Then 'Q2 '
    when datepart(mm, Service_Through_Date ) between '03' and '05' and datepart(mm, paid_date ) between '03' and '05'
    Then 'Q3 '
    when datepart(mm, Service_Through_Date ) between '06' and '08' and datepart(mm, paid_date ) between '06' and '08'
    Then 'Q4 '
    else ' ' end + ' ' + 'FSY ' + '' + cast(datepart(Year, Service_Through_Date)as char(7)) as QTR
    FM

    Your best bet here is going to be to create a calendar table, which has your quarters in it.
    I wrote an article on them here: http://social.technet.microsoft.com/wiki/contents/articles/29260.tsql-calendar-functions-and-tables.aspx.
    For your particular scenario you'll need to add a column to the existing code, something like this:
    SELECT CASE WHEN DATEPART(MONTH,@date) IN (9,10,11) THEN 'FSY'+RIGHT(YEAR(@date)+1,2)+'Q1'
    WHEN DATEPART(MONTH,@date) IN (12) THEN 'FSY'+RIGHT(YEAR(@date)+1,2)+'Q2'
    WHEN DATEPART(MONTH,@date) IN (1,2) THEN 'FSY'+RIGHT(YEAR(@date),2)+'Q2'
    WHEN DATEPART(MONTH,@date) IN (3,4,5) THEN 'FSY'+RIGHT(YEAR(@date),2)+'Q3'
    WHEN DATEPART(MONTH,@date) IN (6,7,8) THEN 'FSY'+RIGHT(YEAR(@date),2)+'Q4'
    END AS fiscalQuarterName
    Once you have this column, you can simply join to the calendar table:
    SELECT service_through_date, paid_date, sc.fiscalQuarterName, pc.fiscalQuarterName
    FROM myTable t
    INNER JOIN calendar sc
    ON t.service_through_date = c.today
    INNER JOIN calendar pc
    ON t.paid_date = pc.today
    If you can't, or don't want to impliment this, you could solve the issue in your cast statement by moving the year into the CASE, like this:
    SELECT CASE WHEN DATEPART(MONTH, Service_Through_Date ) BETWEEN 9 AND 11 AND DATEPART(MONTH, c.paid_date) BETWEEN 9 AND 11 THEN 'FSY'+RIGHT(YEAR(Service_Through_Date)+1,2)+'Q1'
    WHEN DATEPART(MONTH, Service_Through_Date ) = 12 AND DATEPART(MONTH, c.paid_date) = 12 THEN 'FSY'+RIGHT(YEAR(Service_Through_Date)+1,2)+'Q2'
    WHEN DATEPART(MONTH, Service_Through_Date ) BETWEEN 1 AND 2 AND DATEPART(MONTH, paid_date) BETWEEN 1 AND 2 THEN 'FSY'+RIGHT(YEAR(Service_Through_Date),2)+'Q2'
    WHEN DATEPART(MONTH, Service_Through_Date ) BETWEEN 3 AND 5 AND DATEPART(MONTH, paid_date) BETWEEN 3 AND 5 THEN 'FSY'+RIGHT(YEAR(Service_Through_Date),2)+'Q3'
    WHEN DATEPART(MONTH, Service_Through_Date ) BETWEEN 6 AND 8 AND DATEPART(MONTH, paid_date) BETWEEN 6 AND 8 THEN 'FSY'+RIGHT(YEAR(Service_Through_Date),2)+'Q4'
    ELSE 'FSY'+RIGHT(YEAR(Service_Through_Date),2)
    END
    Don't forget to mark helpful posts, and answers. It helps others to find relevant posts to the same question.

  • Case Statement Error - Need help

    What's wrong with this case statement
    Case When Opportunity."Probability %" = '0' then "- Product Revenue"."Product Revenue (000)" *( Opportunity."Probability %" / 100) else "- Product Revenue"."Product Revenue (000)" *( "Opportunity - Product"."Probability %" / 100) end if
    I am getting an error when I place this in a pivot table

    Disregard, it is working now

  • Switch Case Statement Help...

    Hello,
    I am trying to get my pages through Case Statement But...
    Can any one Help me.. here is my code..
    This is my Buttons Code... My buttons are on 1st Frame of My FLA..
    stop();
    btn1.addEventListener(MouseEvent.CLICK, varTest);
    btn2.addEventListener(MouseEvent.CLICK, varTest2);
    function varTest(event:MouseEvent):void
         var page = 1;
         gotoAndStop(20);
    function varTest2(event:MouseEvent):void
         var page = 2;
         gotoAndStop(20);
    and this is my 20th frame code. (here I'm checking variable)
    import flash.events.Event;
    addEventListener(Event.ENTER_FRAME,checkCaseMe);
    function checkCaseMe(event:Event)
         switch (page)
              case "1" :
                   info_txt.text = "page1";
                   break;
              case "2" :
                   info_txt.text = "page1";
                   break;
              default :
                   info_txt.text = "page00";
    When I test the movie.. Error Occured (Scene 1, Layer 'Actions', Frame 21, Line 6 1120: Access of undefined property page. )
    Can Anyone help please.. How do I correct this....???
    Thanks...

    You should learn to use the trace() function to help you troubleshoot code yourself.  In each of your button functions include:
    trace("btn clicked"); // will help you know for sure that the buttons are working
    And in frame 20, you should add a trace as well to determine whether you actually get there when you think you don't...
    trace("in frame 20");
    Lastly, your code for frame 20 is likely not what you need for a couple of reasons...
    1) If you think the ENTER_FRAME listener is used to detect/trigger when the timeline enters a frame, that is not what it does.  What it does is continually process the function that it calls at the frame rate of the file.  It is normally only used when you want to repeatedly trigger some functionality.
    2)  If you assign number values to the page variable, you do not want to use String values in your cases.
    All you should need in frame 20 is...
    switch (page)
         case 1 :
              info_txt.text = "page1";
              break;
         case 2 :
              info_txt.text = "page1";
              break;
         default :
              info_txt.text = "page00";

  • Conditional case statement help.!

    Hello Forum Members,
    I have a table with stores order along with order dates and other information. I have a requirement to write a query to get the nominations from that order's table according to the logic mentioned below.
    Nom1 =  Initial order date and next order within 7 days from initial order date then its considered as R1
    Nom2 = next activity within 7 seven on the same ord_id from its R1 date , this goes on as the order dates increases for same  or single ord_no
    Final Rn  is Count (Rn)
    Rn %-- Count(Rn)  / Count Distinct ( ord_no ) * 100
    Example data output:
    ORD_DATE
    ORD_ID
    1_of_x
    2_of_x
    3_of_x
    4_of_x
    5_of_x
    6_of_x
    Final RnX
    Rn%
    7/10/2013
    10095V1
    1
    0
    0
    0
    0
    0
    8/3/2013
    10095V1
    1
    0
    0
    0
    0
    0
    8/8/2013
    10095V1
    0
    1
    0
    0
    0
    0
    8/12/2013
    10095V1
    0
    0
    1
    0
    0
    0
    9/6/2013
    10095V1
    1
    0
    0
    0
    0
    0
    DDL:
    create table xx_ord_noms
    ord_no varchar(30),
    ord_date date,
    ord_id varchar2(30)
    Sample Data:
    INSERT INTO xx_ord_noms (ord_no, ord_date, ord_id) VALUES ('10091', TO_DATE('07/10/2013','MM/DD/YYYY'), '10091');
    INSERT INTO xx_ord_noms (ord_no, ord_date, ord_id) VALUES ('10091', TO_DATE('08/03/2013','MM/DD/YYYY'), '10091');
    INSERT INTO xx_ord_noms (ord_no, ord_date, ord_id) VALUES ('10091', TO_DATE('08/08/2013','MM/DD/YYYY'), '10091');
    INSERT INTO xx_ord_noms (ord_no, ord_date, ord_id) VALUES ('10091', TO_DATE('08/12/2013','MM/DD/YYYY'), '10091');
    INSERT INTO xx_ord_noms (ord_no, ord_date, ord_id) VALUES ('10091', TO_DATE('09/06/2013','MM/DD/YYYY'), '10091');
    commit;
    I was planning to doing something like this but I am not getting the logic for R1 .. R7
    select ord_no,
           ord_date,
           ord_id,
           prev_dt,
           (to_date(ord_date) - to_date(prev_dt)) data_diff,
           case
             when prev_dt is null or
                  (to_date(ord_date) - to_date(prev_dt)) < 7 then
              'R1'
             when (to_date(ord_date) - to_date(prev_dt)) > 7 THEN
              'R2'
             ELSE
              nULL
           END
      FROM (select a.*,
                   (SELECT MAX(tmp2.ord_date)
                      FROM xx_ord_noms tmp2
                     WHERE a.ord_id = tmp2.ord_id
                       AND tmp2.ord_date < a.ord_date) prev_dt
              from xx_ord_noms a);
    Could someone give me advises or suggestions on how we can get the expected output.
    Thanks in advance.

    LAG and LEAD are good when you want to look forward or back a fixed number of rows, but in this case you don't know how far back you'll need to go.
    I've got a solution. it calculates the Rn as a number, not a column position, but you can transform that with CASE statements if you want. I did it in two main steps:
    First I calculated the Rn by comparing the date of the current and previous row. To do that, I generated a row number using the row_number()  analytic function:
    select ord_no,
           ord_date,
           ord_id,
           numrow
    , Rn
    from xx_ord_noms
    model
      partition by (ord_no)
      dimension by (row_number() over (partition by ord_no order by ord_date)  numrow)
      measures (ord_date, 0 Rn, ord_id )
      rules update
        rn[1] = 1,
        rn[ANY] = CASE when trunc(ord_date[cv()]) - trunc(ord_date[cv() - 1])  < 7 then rn[cv()-1]+1 else 1 end
    ORD_NO     ORD_DATE             ORD_ID         NUMROW         RN
    10091      10-Jul-2013 00:00:00 10091               1          1
    10091      03-Aug-2013 00:00:00 10091               2          1
    10091      08-Aug-2013 00:00:00 10091               3          2
    10091      12-Aug-2013 00:00:00 10091               4          3
    10091      06-Sep-2013 00:00:00 10091               5          1
    Then I needed to identify all the rows of each series. I defined firstDt as the date of the first item in the series:
    firstDt[1] = ord_date[cv()]
    firstDt[ANY] = CASE when rn[cv()]= 1 then ord_date[cv()] else firstDt[cv()-1] end
    With that, the FinalRn is just an analytic max(rn) over (partition by firstDt)
    I'm not clear on what R% is. Your descriptions are unclear and I think they're inconsistent.
    select ord_no, ord_date, ord_id
    , Rn, finalRn, 100*finalRn/totCnt PCT1, 100 * totRn/totCnt PCT2
    , totRn
    from xx_ord_noms
    model
      partition by (ord_no)
      dimension by (row_number() over (partition by ord_no order by ord_date)  numrow)
      measures (ord_date, 0 Rn, ord_id, to_date(null) firstDt, 0 finalRn, 0 totRn, 0 totCnt )
      rules upsert all
        rn[1] = 1
      , rn[ANY] = CASE when trunc(ord_date[cv()]) - trunc(ord_date[cv() - 1])  < 7 then rn[cv()-1]+1 else 1 end
      , firstDt[1] = ord_date[cv()]
      , firstDt[ANY] = CASE when rn[cv()]= 1 then ord_date[cv()] else firstDt[cv()-1] end
      , finalRn[ANY] = max(rn) over (partition by firstDt)
      , totCnt[ANY] = count(*) over()
      , totRn[ANY] = count(case when rn = 1 then 1 else null end) over ()
    ORD_NO     ORD_DATE             ORD_ID             RN    FINALRN       PCT1       PCT2      TOTRN
    10091      10-Jul-2013 00:00:00 10091               1          1         20         60          3
    10091      03-Aug-2013 00:00:00 10091               1          3         60         60          3
    10091      08-Aug-2013 00:00:00 10091               2          3         60         60          3
    10091      12-Aug-2013 00:00:00 10091               3          3         60         60          3
    10091      06-Sep-2013 00:00:00 10091               1          1         20         60          3
    Regards,
    David

  • Formatted search case statement help

    Hi all,
    I am trying to write a case statement in a formatted search, but am running into an error when I add a condition involving the item code. The code works find with the first WHEN statement involving the customer code $[$4.0.0] however, I receive an internal error when I add the second part involving the item code $[$38.1.1] Please advise.
    SELECT
    CASE WHEN $[$4.0.0] = 'C00023'
    THEN 'E002'
    WHEN $[$38.1.1] = 'ItemA'
    THEN 'J002'
    END
    THank you!
    Jane

    Hi Jane,
    Where do you assign this FMS? If it is on the header, the second condition will not work. If it is line level, try change it to $[$38.1.0\].
    Thanks,
    Gordon

  • Case statement help

    Hi Gurus,
    I have a requirement like this,
    I want to extract the service request which closed in last month and opened in the last three months of closing month (close month -3).
    When open month is previous month and timestampdiff(tsi_month, open month(close month), openmonth(close month -3) then nbr of SRs.
    How do i bring the close month in open month value.
    Thanks

    I am trying to enter the following statement for the above requirment
    CASE WHEN "Core"."Close Date"."Close Month" = VALUEOF(PREVIOUS_MONTH) AND TimeStampDiff(SQL_TSI_Month, "Core"."Open Date"."Open Month" = VALUEOF(PREVIOUS_MONTH) , "Core"."Open Date"."Open Month" = VALUEOF(PREVIOUS_MONTH) - 3 ) <= 3 THEN 1 ELSE 0 END
    When i say okay, it gives the error
    [nQSError: 27002] Near <=>: Syntax error [nQSError: 26012] .
    Can anyone help me out.
    Thanks

  • Case structure help needed~

    Hi guys, i am running into some problem trying to output multiple data source into one single indicator, i have attached a screen shot of my schematic below. let's to refer to it...
    i need to run the big case structure after condition is met, but once it is met it will also need to check for certain condition, like '21' and '31' (i have many more) and display whatever constant that is to be displayed, but after i wired it up, it says wire connects to a undirected tunnel. is there is way to wire this sort of logic? i already tried it for quite sometimes, but still couldn't get it to work...
    Thanks in advance for all your help~
    Attachments:
    error9.JPG ‏63 KB

    Simmy,
    1st) Please do not use variables if not really neccessary
    2nd) Think of the wires in LabVIEW just like wires in electronics. Connecting two sources lead to a short. In your case, the short is not obvious since LV didn't typify the outputtunnel from the lower case structure.... which is strange to me, but for usage just as bad as a short....If you like to create a string "21" out of "2" and "1", you have to concatenate the two strings "2" and "1".
    hope this helps,
    Norbert
    Message Edited by Norbert B on 08-01-2008 02:18 AM
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • SQL statement help needed

    I am sure some of you will laugh lol, but I am drawing a blank and need some assistance if anyone is willing to help:
    I have this query:
    SELECT DISTINCT ID
    FROM (SELECT productcode
    FROM sforce_product2
    WHERE productcode NOT LIKE 'DSXXX%'
    AND productcode NOT LIKE 'DO NOT USE%'
    AND productcode NOT LIKE 'MAXXXX%'
    AND isactive = 'true'
    MINUS
    SELECT productcode
    FROM vew_product_export) a,
    sforce_product2
    WHERE a.productcode = sforce_product2.productcode
    which returns 112 ID's (which is wrong)
    The inner SELECT statement:
    SELECT productcode
    FROM sforce_product2
    WHERE productcode NOT LIKE 'DSXXX%'
    AND productcode NOT LIKE 'DO NOT USE%'
    AND productcode NOT LIKE 'MAXXXX%'
    AND isactive = 'true'
    MINUS
    SELECT productcode
    FROM vew_product_export
    returns 106.
    Am I doing something simple wrong or is my query just mangled!
    TIA,
    Mike

      SELECT DISTINCT ID
        FROM (SELECT productcode
                FROM sforce_product2
               WHERE productcode NOT LIKE 'DSXXX%'
                 AND productcode NOT LIKE 'DO NOT USE%'
                 AND productcode NOT LIKE 'MAXXXX%'
                 AND isactive = 'true'
              MINUS
              SELECT productcode
                FROM vew_product_export) a,
              sforce_product2
       WHERE a.productcode = sforce_product2.productcodethe above code is returning an ID column which i think most probable from the sforce_product2 table
    while this query below returns the 106 value that is coming from the column productcode.
      SELECT productcode
        FROM sforce_product2
       WHERE productcode NOT LIKE 'DSXXX%'
         AND productcode NOT LIKE 'DO NOT USE%'
         AND productcode NOT LIKE 'MAXXXX%'
         AND isactive = 'true'
      MINUS
      SELECT productcode
        FROM vew_product_exportso i think there is nothing wrong because if you will review the 112 is from the column ID while the 106 is from the column productcode.

  • ?? Invalid Cursor State - Help needed in JSP.

    OK...here's the problem I have a page that loads the values from a database into input fields so as users could edit and update the data into the respective tables.
    But the problem is i get this error which I have never come accross before. So any help clarifying this would be much appreciated.
    The stack trace :
    500 Internal Server Error
    java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
         at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6106)
         at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6263)
         at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.java:3307)
         at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(JdbcOdbcResultSet.java:5492)
         at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:342)
         at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:399)
         at /abb/jspages/editCosting.jsp._jspService(/abb/jspages/editCosting.jsp.java:40) (JSP page line 13)
         at com.orionserver[Orion/2.0.2 (build 11157)].http.OrionHttpJspPage.service(.:70)
         at com.evermind[Orion/2.0.2 (build 11157)]._ay._rkb(.:5741)
         at com.evermind[Orion/2.0.2 (build 11157)].server.http.JSPServlet.service(.:31)
         at com.evermind[Orion/2.0.2 (build 11157)]._cub._pod(.:521)
         at com.evermind[Orion/2.0.2 (build 11157)]._cub._bmc(.:177)
         at com.evermind[Orion/2.0.2 (build 11157)]._ax._ltc(.:666)
         at com.evermind[Orion/2.0.2 (build 11157)]._ax._uab(.:191)
         at com.evermind[Orion/2.0.2 (build 11157)]._bf.run(.:62)By the way I am using Microsoft Access as the DB and Orion Server 2.0.2.

    sorry guys...It was me who's the stupid one gocha. Actually there error was caused by a typo i made in the rs.next codings.
    Since i just copied it from another well functioning coding i didn't check for typos in the coding. Maybe i accidentally pressed something on the keyboard.
    Thanks for the help guys..I really appreciate it.

  • SQL Case statement Help....

    Hi , I have to Compare two columns to see if they are matching or not....and give the count() of overrides if they are not matching/
    I have got that with the below SQL:
    Count of Overrides =
    select count(Case when Col_1 != Col_2 then 1 else null end) Overrides
    from table_1, table_2
    where table_1.id = table_2.id
    But now i have to look at two columns and get the count()
    I have
    col_1 and col_2 in table_1 and
    col_3 and col_4 in table_2
    (I have to compare col_1 with col_2 and...... col_3 with col_4 and if either of them is not matching.... count it as an override
    Will the following SQL return correct values?
    Count of Overrides =
    Select
    Count( Case when (col_1 ! = col_2) or (col_3 != col_4) then 1 else null end) Overrides
    from table_1, table_2
    where table_1.id = table_2.id
    Thanks

    "yes, it can be rewritten as a decode. but why bother?"
    Well, although I do like Sy's code better, the decode version does naturally handle NULLs unlike the case.
    SQL> WITH t AS (
      2     SELECT 1 col_1, 1 col_2, 2 col_3, 2 col_4 FROM dual UNION ALL
      3     SELECT 1, 1, 2, 3 FROM dual UNION ALL
      4     SELECT 1, 2, 3, 3 FROM dual UNION ALL
      5     SELECT null, 1, 2, 2 FROM dual UNION ALL
      6     SELECT 1, 1, 2, null FROM dual UNION ALL
      7     SELECT 1, 2, 3, 4 FROM dual)
      8  SELECT col_1, col_2, col_3, col_4,
      9         CASE WHEN (col_1 ! = col_2) or (col_3 != col_4) then 1 else null end Ocase,
    10         DECODE(col_1, col_2, DECODE(col_3, col_4, NULL, 1), 1) odecode
    11  FROM t;
         COL_1      COL_2      COL_3      COL_4      OCASE O
             1          1          2          2
             1          1          2          3          1 1
             1          2          3          3          1 1
                        1          2          2            1
             1          1          2                       1
             1          2          3          4          1 1John

  • Simple SQl statement help needed!!!

    New to SQL..Please can you advice where is the problem..
    select file_id, a.file_name, a.sum(bytes/1024/1024) Used_space, b.sum(bytes/1024
    /1024) Free_space from dba_data_files a, dba_free_space b where tablespace_name
    ='DATA_TS' OR tablespace_name='INDEX_TS' OR tablespace_name='LOB_TS' group by fi
    le_id
    ERROR at line 1:
    ORA-00918: column ambiguously defined
    Thanks!

    Hi,
    Should you chose to format your SQL the problem is easily seen:
    SQL>select file_id
      2          ,a.file_name
      3          ,a.sum(bytes / 1024 / 1024) used_space
      4          ,b.sum(bytes / 1024 / 1024) free_space
      5      from dba_data_files a, dba_free_space b
      6     where tablespace_name = 'DATA_TS'
      7        or tablespace_name = 'INDEX_TS'
      8        or tablespace_name = 'LOB_TS'
      9  group by file_id;
    group by file_id
    ERROR at line 9:
    ORA-00918: column ambiguously defined
    SQL>So, which file_id do you want - a or b?
    Regards
    Peter

  • SQL Query CASE statement using two fields

    Hi,
    I have two fields. One is called rescategory1, the other is called rescategory2.
    I'm not sure if its a CASE statement I need or some sort of WHERE clause but I want to create a query that does the following or something similar:
    CASE rescategory2
    WHEN rescategory1 = '44' AND rescategory2 = '1' THEN 'Backup'
    WHEN rescategory1 = '44' AND rescategory2 = '2' THEN 'Hardware'
    END AS [Resolution Sub Category]
    Basically, I'm looking to give rescategory2 a value based on that of rescategory1 and rescategory2 combined.
    How do I write this?
    Cheers
    Paul

    do you mean this?
    rescategory2 = CASE
    WHEN rescategory1 = '44' AND rescategory2 = '1' THEN 'Backup'
    WHEN rescategory1 = '44' AND rescategory2 = '2' THEN 'Hardware'
    END
    ie assigning value for rescategory2
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Need help on case statements to validate records

    Hi Experts ,
    My table :
    seq_num
    col2
    col3
    col4
    1
    A
    12345
    P
    2
    B
    1
    123%23
    3
    C
    1
    23AB
    4
    D
    1
    20131001
    5
    E
    1
    6
    A
    13245
    Q
    7
    B
    1
    12345
    8
    C
    2
    1234*AB
    9
    D
    5
    20140112
    10
    E
    1
    00020
    my output
    seq_num
    col2
    col3
    col4
    Status
    Reason
    1
    A
    12345
    P
    Valid
    2
    B
    1
    123%23
    invalid
    Special Character for col4
    3
    C
    1
    23AB
    Valid
    4
    D
    1
    20131001
    Valid
    5
    E
    1
    invalid
    null for col4
    6
    A
    13245
    Q
    invalid
    Invalid character col4 || invalid number for col3
    7
    B
    1
    12345
    Valid
    8
    C
    2
    1234*AB
    Invalid
    Special Character col4 ||invalid col3
    9
    D
    5
    20140112
    invalid
    Future dates col4 ||invalid col3
    10
    E
    1
    00020
    Valid
    Sql :
    with t as
    ( select 1 as seq_num,'A' as col2 ,12345 as col3 ,'P' as col4 from dual
    union all
    select 2 ,'B',1,'123%23' from dual
    union all
    select 3,'C',1,'23AB' from dual
    union all
    select 4,'D',1,'21-02-2013' from dual
    union all
    select 5,'E',1,null from dual
    union all
    select 6,'A,13245,'Q' from dual
    union all
    select 7,'B',1,12345 from dual
    union all
    select 8,'C',2,'1234*AB' from dual
    union all
    select 9,'D',5,'25-01-2014' from dual
    union all
    select 10,'E',1,20 from dual
    I am applying rules on col3 and col4 for each records row-wise.
    I need case statements to populate status and reason columns after applying below rules
    Rules
    Col3 :
    For A record ,it should be 12345 always .
    For B,C,D,E , record should be always 1
    col4
    For A record , it should be either P or R
    No null values for all A, B,C,D,E records
    for B record , it dont contain special charecters
    for C RECORD ,  it dont contain special charecters
    for D record ,it should not contain future dates (dates are in yyyymmdd format and  less than  sysdates are valid )
    I have other columns as well ,as i not included here
    .It would be great if you Could  help on case statements
    Thanks and Regards,
    Sumanth

    I've adjusted Gregs nice example a bit. This should work:
    with w_base as (
          select seq_num, col2, col3, col4,
                 case when (col2 = 'A'                 AND col3 = 12345 )
                        OR (col2 in ('B','C','D','E')  AND col3 = 1)
                            then '' else '||invalid col3' end ||
                 case when (col2 = 'A'        AND col4 not IN ( 'P', 'R' ) )
                            then '||invalid col4' else '' end ||
                 case when (col2 IN ( 'B', 'C' )   AND col4 != translate(col4, 'a!@#$%^*()','a') )
                            then '||special character for col4' else '' end ||
                 case when (col2 = 'D'        AND col4 >= to_char(sysdate,'yyyymmdd') )
                            then '||future dates col4' else '' end
                   reason
          from ( select 1 as seq_num, 'A' as col2, 12345 as col3, 'P' as col4  from dual union all
                 select 2,            'B',         1,             '123%23'     from dual union all
                 select 3,            'C',         1,             '23AB'       from dual union all
                 select 4,            'D',         1,             '20130212'   from dual union all
                 select 5,            'E',         1,             null         from dual union all
                 select 6,            'A',         13245,         'Q'          from dual union all
                 select 7,            'B',         1,             '12345'      from dual union all
                 select 8,            'C',         2,             '1234*AB'    from dual union all
                 select 9,            'D',         5,             '20140125'   from dual union all
                 select 10,           'E',         1,             '20'         from dual )
    Select seq_num, col2, col3, col4,
           case when reason is null then 'Valid' else 'Invalid' end status,
           substr(reason, 3 ) reason
    from w_base
    It returns
    SEQ_NUM
    COL2
    COL3
    COL4
    STATUS
    REASON
    1
    A
    12345
    P
    Valid
    2
    B
    1
    123%23
    Invalid
    special character for col4
    3
    C
    1
    23AB
    Valid
    4
    D
    1
    20130212
    Valid
    5
    E
    1
    Valid
    6
    A
    13245
    Q
    Invalid
    invalid col3||invalid col4
    7
    B
    1
    12345
    Valid
    8
    C
    2
    1234*AB
    Invalid
    invalid col3||special character for col4
    9
    D
    5
    20140125
    Invalid
    invalid col3||future dates col4
    10
    E
    1
    20
    Valid
    edited some bugs :) now it should be fine! really

Maybe you are looking for

  • Everytime i open some websites, it displays the page for a while then load to another blank page.

    hai. i need help. and just for heads up, i;m not computer/tech savvy. i dont remember when this problem was started (maybe around 2 or 3 months ago) but everytime i opened some sites, the page displayed for a while then it reload itself and shown a b

  • What happens to the users when ISE is reloaded?

    Hello, We have a need to reload ISE and I am wondering what the end user experience would be.  Will they be booted from the network or will the reload be transparent to them? Version: 1.2.0.899 Patch Information: 1,2 Please let me know if there is mo

  • OSB 11g - Conditional Branch Problem using attribute selection

    Folks, Came across a problem using OSB Conditional Branch using attribute selection, it fails & is most likely a bug. It was bug in ALSB2.5 but read in forums was fixed in ALSB 2.6 things I am doing - 1. In the Msg Flow, Conditional branch is @ the s

  • Extended warranty for Satellite A300-15C

    Hi I am new here so sorry if I posted it under wrong thread. I want to buy extended warranty for Satellite A300-15C (1+1 standard warranty) so I wanna ask which warranty package gives the longest protection for this model. 2+2 is the longest? ID: SE5

  • Premiere Pro Debug Event trackitemgroup

    In Premiere Pro 5.5, I get a Premiere Pro Debug Event ending in "trackitemgroup.h-2" that crashes the program every time the project is opened.  Premiere will open other projects/create new projects, and importing the sequence and media into a new fo