Case Statement @ Switch Statement Need Help !

     private boolean n, e, s, w;
     private int pointer;
public void setLinks(int pointer)
          if (pointer == 0)
               n=false; e=false; s=false; w=false;
          else if(pointer == 1)
               n=true; e=true; s=false; w=false;
          else if(pointer == 2)
               n=false; e=false; s=true; w=true;
          else if(pointer == 3)
               n=false; e=true; s=true; w=false;
          else if(pointer == 4)
               n=true; e=false; s=false; w=true;
          else if(pointer == 5)
               n=true; e=false; s=true; w=false;
          else if(pointer == 6)
               n=false; e=true; s=false; w=true;
          else if(pointer == 7)
               n=true; e=true; s=true; w=true;
          else if(pointer == 8)
               n=false; e=true; s=true; w=true;
          else if(pointer == 9)
               n=true; e=false; s=true; w=true;
          else if(pointer == 10)
               n=true; e=true; s=false; w=true;
          else if(pointer == 11)
               n=true; e=true; s=true; w=false;
     }Plz advice me how to change this statement into a case/switch statement

multi post
http://forum.java.sun.com/thread.jspa?threadID=5277360&tstart=0

Similar Messages

  • Switch method need help please ;-(

    Hello, I am having trouble with this switch method. I have yet ot construct the AirplaneList object "plane". For I have yet to be taught about it properly
    Can someone at least help me with the switch incident. I have learnt how to make a menu for the user to input the letters A-F in uppercase and lower case. However I am unsure on how to associate "case a" to the method
    //add Airplane
    public static void option1 (AirplaneList plane)
    ? I can get it to print out "case a" continueosly, but how to I associate it to the method. I am aware that the AirplaneList will be a class I have to define earlier, and that "plane" is an object I will need to intiate. If anyone will be willing to help me construct this part of the code I can award them Duke dollars.
    as far as I can tell the constructor method would start off like
    AirplaneList plane = new AirplaneList;
    ok? then what do I do?
    do I define its methods then?
    plane.add()
    Ok well this is the majority of the code I have already.
    import javax.swing.JOptionPane; //indicates that the compiler should load class JOptionPane for use in this application.
    public class AirplaneListT
         public static void main (String[] args)
    throws java.io.IOException
              char choice; //Words choice and size are the names of variables
         //     int size; //This declaration specifies that the variable are of data type char and int
         //     size = EasyIn.getInt(); // Converts size from int to something?
         //Char - a variable that may only hold a single lowercase letter, a single uppercase letter, a single digit or a special character
    //(such as x, $, 7 and *)
         // The code below creates a dialog box for the user to input a choice
         String inputcode;
         inputcode = JOptionPane.showInputDialog("A: add an airplane from the list\n" +
                                  "B: remove an airplane from the list\n" +
                                  "C: check if the list is empty\n" +
                                  "D: check if the list is full\n" +
                                  "E: display the list\n" +
                                  "F: quit\n" );
         JOptionPane.showMessageDialog(null, "You have chosen choice " + inputcode);
    //The null first argument indicates that the message dialog will appear in the center of the screen. The 2nd is the message to display
    do
         // get choice from user
         choice = inputcode.toUpperCase().charAt(0);
              System.out.println();
              //process menu options
              switch(choice)
                   case 'A':
                   case 'a':
                        JOptionPane.showMessageDialog(null, "Case " + inputcode);
                        break;     //done processing case
                   case 'B':
                   case 'b':
                        JOptionPane.showMessageDialog(null, "Case " + inputcode);
                        break;     //done processing case
                   case 'C':
                   case 'c':
                        JOptionPane.showMessageDialog(null, "Case " + inputcode);
                        break;     //done processing case
                   case 'D':
                   case 'd':
                        JOptionPane.showMessageDialog(null, "Case " + inputcode);
                        break;     //done processing case
                   case 'E':
                   case 'e':
                        JOptionPane.showMessageDialog(null, "Case " + inputcode);
                        break;     //done processing case
                   case 'F':
                   case 'f':
                        JOptionPane.showMessageDialog(null, "Case " + inputcode);
                        break;     //done processing case
                   default:
                        JOptionPane.showMessageDialog(null, "Invalid entry!");
                        break;     //done processing case
         }while (choice!= 'F' || //end AirplaneList tester
         choice!= 'f' );
    //add Airplane
         public static void option1 (AirplaneList plane)
              String flight;
              flight = JOptionPane.showInputDialog("Please enter airplane filght number" );
              //create an Airplane object to add to list
              Airplane flight = new Airplane();
              //add string to list if the list is not full
              //access the 'add(Airplane)' method from the AirplaneList class;
              //if the list is full, return a statement to the user indicating that no more plane can be added onto the list
         //remove airplane
         public static void option2 ()
              //get position of item
         string enterpos;
         enterpos = JOptionPane.showInputDialog("Please enter position to remove" );
              System.out.print(":")
              int plane = Easyln.getint();
              // delete item if it exists
              //access the 'remove(Airplane)' method from the AirplaneList class;
              //if the user enter an invalid number for the position, returen a statement
              //indicating that there is no such posititon.
         //check if empty
         public static void option3 (AirplaneList plane)
              if (plane.isEmpty())
                   JOptionPane.showInputDialog("list is empty" );
              else
                   JOptionPane.showInputDialog("list is not empty" );
         //check if full
         public static void option4 (AirplaneList plane)
              if (plane.isFull())
                   JOptionPane.showInputDialog("list is full" );
              else
                   JOptionPane.showInputDialog("list is not full" );
         //display list
         public static void option5 (AirplaneList plane)
              if (plane.isEmpty())     //no need to display if list is empty
                   JOptionPane.showInputDialog("list is empty" );
              else
                   JOptionPane.showInputDialog("Airplanes in list are" );
                   //loop through list
         System.exit(0); //Terminates the program

    case 'A':
    case 'a':
    JOptionPane.showMessageDialog(null, "Case " + " + inputcode);
    break;     //done processing case
    ok are u saying if i invoke a method i go something
    like this?
    case 'A':
    case 'a':
    JOptionPane.showMessageDialog(null, "Case " + " + inputcode);
    AirplaneList.option1(); //Tell Airplanelist to add                    
    break;     //done processing caseIn both cases, you're calling methods. In the latter case, you're calling two methods.
    What's the problem exactly? What part are you having trouble with?
    ... so that then when case a is activated it should go
    onto option1 method?That's one thing you can do, yes. I don't know if you should do it. It depends on what your program needs to do.
    //add Airplane
         public static void option1 (AirplaneList plane)
              String flight;
    flight = JOptionPane.showInputDialog("Please enter
    r airplane filght number" );
              //create an Airplane object to add to list
              Airplane flight = new Airplane();
              //add string to list if the list is not full
    //access the 'add(Airplane)' method from the
    e AirplaneList class;
    //if the list is full, return a statement to the
    e user indicating that no more plane can be added onto
    the list
         }OK, this looks odd. Is this what you're having trouble with?
    BTW, I'd strongly suggest making a stronger separation of application code from GUI code.

  • I was google mapping and my ipad bacame hung. Can neither exit nor switch off. need help!

    I was google mapping and my ipad hang. Can neither exit nor switch off. Any advice on what's gone wrong?

    Try a restart:
    To restart (reboot) Press and Hold the Home and Power buttons until the Apple Logo appears, about 10 seconds.

  • Need help - Catalyst 3550 on CCM4.1 Voip

    Guys.
    We had a Catalyst 3550 switch fail last week, and the guy who really knows this system has left the company.
    The switch has a non-free molecules error, which i believe is terminal.
    I've sourced a replacement switch and need help configuring it.
    I copied the running config from it's sister switch (there are only 2 switches on this ccm), however, the sister switch is a 3560.
    I changed the I.P address and switch name before uploading it to the 3550 on the off chance it might just work.
    Show run on the 3550 shows that it might be configured, but when i connected it, it took the gateway down.
    I'm really up the creek at the moment unless i can get someone to either look at it, find an old config or get this guy back in for a few hours.
    Any advice would be greatly received.
    Looking at show run, i see two refernces to VLAN's
    interface Vlan1
     ip address 170.205.238.3 255.255.255.0
    interface Vlan10
     ip address 10.10.0.254 255.255.255.0
    ip classless
    ip route 0.0.0.0 0.0.0.0 170.205.238.1
    no ip http server
    The I.P address 170.205.238.1 is alien to me.. i don't know what this is. However, what i do know is that i never changed this. This IP address is the same in the 3560.
    Could this cause an issue ?. I'm not aware of anything on a 170.X.X.X subnet, this could have been some legacy from the previous owners of the building.
    The first 3 ports in the switch are connected to the publisher, subscriber and gateway router.
    Does it matter which port is connected to which component. ?
    I believe that i can't be too far away from configuring this, but without any help, i'm a bit stuck.
    LEE-SW-CC_VOIP-01#show run
    Building configuration...
    Current configuration : 6147 bytes
    version 12.1
    no service pad
    service timestamps debug datetime msec
    service timestamps log datetime msec
    service password-encryption
    hostname LEE-SW-CC_VOIP-01
    enable secret 5 $1$2BRP$UtiYkRMAsp7roykkfRDo3/
    username cisco privilege 15 secret 5 $1$mh3w$w8H5ygAfDUOBdiE2UftB8.
    ip subnet-zero
    ip routing
    vtp domain LEE
    vtp mode transparent
    mls qos map cos-dscp 0 8 16 26 32 46 48 56
    mls qos
    no file verify auto
    spanning-tree mode pvst
    spanning-tree extend system-id
    vlan 10
    interface FastEthernet0/1
     switchport access vlan 10
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/2
     switchport access vlan 10
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/3
     switchport access vlan 10
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/4
     switchport access vlan 10
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/5
     switchport access vlan 10
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/6
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/7
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/8
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/9
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/10
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/11
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/12
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/13
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/14
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/15
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/16
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/17
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/18
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/19
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/20
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/21
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/22
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/23
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface FastEthernet0/24
     switchport mode access
     switchport voice vlan 10
     no ip address
     mls qos trust device cisco-phone
     mls qos trust cos
     auto qos voip cisco-phone
     spanning-tree portfast
    interface GigabitEthernet0/1
     switchport trunk encapsulation dot1q
     switchport mode trunk
     no ip address
     mls qos trust cos
     udld port aggressive
     auto qos voip trust
    interface GigabitEthernet0/2
     switchport trunk encapsulation dot1q
     switchport mode trunk
     no ip address
     mls qos trust cos
     udld port aggressive
     auto qos voip trust
     priority-queue out
    interface Vlan1
     ip address 170.205.238.3 255.255.255.0
    interface Vlan10
     ip address 10.10.0.254 255.255.255.0
    ip classless
    ip route 0.0.0.0 0.0.0.0 170.205.238.1
    no ip http server
    logging trap debugging
    line con 0
     exec-timeout 0 0
     privilege level 15
     login local
    line vty 0 4
     privilege level 15
     login local
     length 0
    line vty 5 15
     privilege level 15
     login local
     length 0
    end
    LEE-SW-CC_VOIP-01#

    Always wanting to learn more, I re-instated the test config and ran those commands.
    LEE-SW-CC_VOIP-01#show cdp neighbor
    Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge
                      S - Switch, H - Host, I - IGMP, r - Repeater, P - Phone
    Device ID        Local Intrfce     Holdtme    Capability  Platform  Port ID
    LEE-SW-CC_VOIP-01#show ip int brief
    Interface                  IP-Address      OK? Method Status                Prot
    ocol
    Vlan1                      170.205.238.2   YES NVRAM  up                    down
    Vlan10                     10.10.0.254     YES NVRAM  up                    down
    FastEthernet0/1            unassigned      YES unset  down                  down
    FastEthernet0/2            unassigned      YES unset  down                  down
    FastEthernet0/3            unassigned      YES unset  down                  down
    FastEthernet0/4            unassigned      YES unset  down                  down
    FastEthernet0/5            unassigned      YES unset  down                  down
    FastEthernet0/6            unassigned      YES unset  down                  down
    FastEthernet0/7            unassigned      YES unset  down                  down
    FastEthernet0/8            unassigned      YES unset  down                  down
    FastEthernet0/9            unassigned      YES unset  down                  down
    FastEthernet0/10           unassigned      YES unset  down                  down
    FastEthernet0/11           unassigned      YES unset  down                  down
    FastEthernet0/12           unassigned      YES unset  down                  down
    FastEthernet0/13           unassigned      YES unset  down                  down
    FastEthernet0/14           unassigned      YES unset  down                  down
    FastEthernet0/15           unassigned      YES unset  down                  down
    FastEthernet0/16           unassigned      YES unset  down                  down
    FastEthernet0/17           unassigned      YES unset  down                  down
    FastEthernet0/18           unassigned      YES unset  down                  down
    FastEthernet0/19           unassigned      YES unset  down                  down
    FastEthernet0/20           unassigned      YES unset  down                  down
    FastEthernet0/21           unassigned      YES unset  down                  down
    FastEthernet0/22           unassigned      YES unset  down                  down
    FastEthernet0/23           unassigned      YES unset  down                  down
    FastEthernet0/24           unassigned      YES unset  down                  down
    GigabitEthernet0/1         unassigned      YES unset  down                  down
    GigabitEthernet0/2         unassigned      YES unset  down                  down
    LEE-SW-CC_VOIP-01#

  • 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";

  • 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

  • Need help converting Excel IF statement into CASE WHEN statement for Oracle

    Hi,
    Hope someone can help I have tried various ways of getting this to work, to no avail!
    Bascially I have some figures that are minus figures, and I need to add them together to get a movement figure, but I need to treat the minus figures as minus, if that makes sense, rather than the usual... a minus and a minus makes a plus.
    For example:- Budget Figure = -1% and Actual Figure = -68% so the movement needs to be -69%.
    The IF statement I have been using in Excel is the following:-
    =IF(FO110<0,(FP110-(IF(FO110=0,1,FO110)*-1)),FP110-IF(FO110=0,1,FO110))
    Which when using the figures as above = -69%
    Cell FO = The Budget Figure
    Cell FP = The Actual Figure
    However, when I created the CASE statement in Oracle, the figure in the query comes back as -0.67, which is oviously not what I want to happen when both actual and budget are minus figures; however when they are a minus and a plus, it works perfectly fine.
    Any help on this would be most appreciated!
    Kind regards,
    Annmarie

    Happy I did'n mess something up :)
    Nevertheless, don't show it too much around because
    case when budget < 0
         then actual - case when budget = 0  /* will never happen */
                            then 1           /* will never happen */
                            else budget
                       end * (-1)            /* -budget * (-1) remains only */
         else actual - case when budget = 0
                            then 1
                            else budget
                       end
    endso at least try the following (if case is more readable as decode for you). Let's hope it works as I don't have a Database at hand
    case when budget < 0
         then actual + budget
         else actual - case when budget = 0
                            then 1
                            else budget
                       end
    end Regards
    Etbin

  • 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 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.

  • Need help in this sql query to use Case Statement

    hi All,
    I have the below query -
    SELECT DISTINCT OFFC.PROV_ID
    ,OFFC.WK_DAY
    ,CASE
    WHEN OFFC.WK_DAY ='MONDAY' THEN 1
    WHEN OFFC.WK_DAY ='TUESDAY' THEN 2
    WHEN OFFC.WK_DAY ='WEDNESDAY' THEN 3
    WHEN OFFC.WK_DAY ='THURSDAY' THEN 4
    WHEN OFFC.WK_DAY ='FRIDAY' THEN 5
    WHEN OFFC.WK_DAY ='SATURDAY' THEN 6
    WHEN OFFC.WK_DAY ='SUNDAY' THEN 7
    END AS DOW
    ,OFFC.OFFC_OPENG_TIME
    ,OFFC.OFFC_CLSNG_TIME
    FROM GGDD.PROV_OFFC_HR OFFC
    WHERE OFFC.PROV_ID='0000600'
    WITH UR;
    this query is bringing results in 6 differnt rows with opening and closing time for each day separately. I want to generate the data in one row with each day having opening and closing time, so for 7 days, total 14 columns with opening and closing time. But i am not able to do that using case statement.
    can somebody help me in achieving that.
    thanks,
    iamhere

    Hi,
    Welcome to the forum!
    That's called a Pivot .
    Instead of having 1CASE expression, have 14, one for the opening and one for the closing time each day, and do GROUP BY to combine them onto one row.
    SELECT       OFFC.PROV_ID
    ,       MIN (CASE WHEN OFFC.WK_DAY ='MONDAY'    THEN OFFC.OFFC_OPENG_TIME END)     AS mon_opn
    ,       MIN (CASE WHEN OFFC.WK_DAY ='MONDAY'    THEN OFFC.OFFC_CLSNG_TIME END)     AS mon_cls
    ,       MIN (CASE WHEN OFFC.WK_DAY ='TUESDAY'   THEN OFFC.OFFC_OPENG_TIME END)     AS tue_opn
    ,       MIN (CASE WHEN OFFC.WK_DAY ='TUESDAY'   THEN OFFC.OFFC_CLSNG_TIME END)     AS tue_cls
    FROM        GGDD.PROV_OFFC_HR OFFC
    WHERE       OFFC.PROV_ID     = '0000600'
    GROUP BY  offc.prov_id
    ;This assumes there is (at most) only one row in the table for each distinct prov_id and weekday. If not, what do you want to do? Post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
    The staement above works in Oracle 8.1 and up, but there's a better way (SELECT ... PIVOT) available in Oracle 11. What version are you using? (It's always a good idea to include this when you post a question.)
    Edited by: Frank Kulash on Jan 6, 2011 8:22 PM

  • Need help in this query using Case Statement

    I have the following query which is currently existing and I am adding few more conditions based on the new requirements which is based on a particular flag set as 1 or 0.
    If it is set to 1 then I should use the old query as it is and if it is set to 0 then I should add the new conditions.
    Basically when the flag is set to 0, I shouldnt be including some of the records that already exists and should include only new records. This is based on the plan_type_ids in (1,2,3,4).
    Hence I am using the Case statement to check if the plan_type_id is in (1,2) then do a set of not exists and if the plan_type_id in (3,4) then do set of not exists.
    But when I run this query it is giving me error. What am I doing wrong?
    Is there any other simple way to combine all the not exists for all of those select statements as given after the line ------------------------- into a single one?
    What am I doing wrong?
    I tried putting the NOT EXists before the case too but that too didnt work.
    Please help. Appreciate it.
    Thank you in advance.
    SELECT
    ee.employee_id
    ,'WELCOMEMSG'
    ,DECODE( me.member_enrollment_id
    ,first_enr.enrollment_id
    ,20
    ,23
    ) status_id
    ,me.member_enrollment_id
    ,wk.welcome_msg_id
    FROM wk
    ,employees ee
    ,MEMBER_ENROLLMENTS me
    ,plans pl
    ,( SELECT employee_id
    ,plan_type_id
    ,start_date
    ,plan_id
    ,MIN(MEMBER_ENROLLMENT_ID) member_enrollment_id
    FROM ( SELECT me.employee_id
    ,DECODE(pl.plan_type_id,1,2,pl.plan_type_id) plan_type_id
    ,pl.start_date
    ,wk.plan_id
    ,me.member_enrollment_id
    FROM wk
    ,PLANS pl
    ,MEMBER_ENROLLMENTS me
    WHERE wk.done_by = nvl('TEST' ,wk.done_by)
    AND wk.welcome_msg_name <> 'NONE'
    AND pl.employer_id = wk.employer_id
    AND wk.employer_id = 5
    AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
    AND pl.plan_id = NVL(wk.plan_id,pl.plan_id)
    AND me.plan_id = pl.plan_id
    AND me.coverage_effective_date <> NVL(me.coverage_end_Date, me.coverage_effective_date + 1)
    AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
    MINUS
    SELECT me.employee_id
    ,DECODE(pl.plan_type_id,1,2,pl.plan_type_id) plan_type_id
    ,pl.start_date
    ,NULL plan_id
    ,me.member_enrollment_id
    FROM wk
    ,PLANS pl
    ,MEMBER_ENROLLMENTS me
    WHERE wk.done_by = nvl(NULL,wk.done_by)
    AND wk.welcome_msg_name <> 'NONE'
    AND pl.employer_id = wk.employer_id
    AND wk.employer_id = 5
    AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
    AND pl.plan_id = wk.plan_id
    AND me.plan_id = pl.plan_id
    AND me.coverage_effective_date <> NVL(me.coverage_end_Date, me.coverage_effective_date + 1)
    AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
    WHERE employee_id = 100
    GROUP BY employee_id ,plan_type_id,start_date ,plan_id
    )first_enr
    ,MEMBER_EVENTS mv
    WHERE wk.done_by = nvl(NULL,wk.done_by)
    AND wk.employer_id = ee.employer_id
    AND ee.employee_id = me.employee_id
    AND ee.employee_id = 100
    AND me.plan_id = pl.plan_id
    AND me.coverage_effective_date <> NVL(me.coverage_end_Date, me.coverage_effective_date + 1)
    AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
    AND is_expired(me.employee_id,me.plan_id) = 'Y'
    AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
    AND pl.plan_id=nvl(wk.plan_id,pl.plan_id)
    AND me.employee_id = first_enr.employee_id
    AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = first_enr.plan_type_id
    AND pl.start_date = first_enr.start_date
    AND me.member_enrollment_id = mv.member_enrollment_id (+)
    AND 'WELCOMEMSG' = mv.event_name(+)
    AND mv.member_enrollment_id IS NULL
    AND wk.welcome_msg_name <> 'NONE'
    AND NVL(first_enr.plan_id,0) = NVL( wk.plan_id,0)
    AND (FN_get_all_participant(wk.employer_id) = 1
    OR
    (FN_get_all_participant(wk.employer_id) = 0
    AND (CASE WHEN pl.plan_type_id IN (1,2)
    THEN NOT EXISTS (SELECT 'X'
    FROM member_accounts ma
    member_enrollments men3
    plans pl3
    plan_types pt3
    WHERE ma.member_account_id = men3.member_account_id
    AND ma.employee_id = me.employee_id
    AND ma.plan_id = pl3.plan_id
    AND pl3.start_date < pl.START_DATE
    AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
    AND pl3.plan_type_id = pt3.plan_type_id
    AND pt3.plan_type_id in (1, 2)
    UNION
    (SELECT 'X'
    FROM member_accounts ma
    member_enrollments men3
    plans pl3
    plan_types pt3
    WHERE ma.member_account_id = men3.member_account_id
    AND ma.employee_id = me.employee_id
    AND ma.plan_id = pl3.plan_id
    AND pl3.start_date = (pl.start_date - 365)
    \ AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
    AND pl3.plan_type_id = pt3.plan_type_id
    AND pt3.plan_type_id = wk.plan_type_id
    UNION
    (SELECT 'X'
    FROM member_accounts ma
    member_enrollments men3
    plans pl3
    plan_types pt3
    WHERE ma.member_account_id = men3.member_account_id
    AND ma.employee_id = men2.employee_id
    AND ma.plan_id = pl3.plan_id
    AND pl3.start_date < pl2.START_DATE -- '01-Jan-2011'
    AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
    AND pl3.plan_type_id = pt3.plan_type_id
    AND pt3.plan_type_id = 2
    UNION
    (SELECT 'X'
    FROM member_accounts ma
    member_enrollments men3
    plans pl3
    plan_types pt3
    WHERE ma.member_account_id = men3.member_account_id
    AND ma.employee_id = men2.employee_id
    AND ma.plan_id = pl3.plan_id
    AND pl3.start_date < pl2.START_DATE -- '01-Jan-2011'
    AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
    AND pl3.plan_type_id = pt3.plan_type_id
    AND pt3.plan_type_id = 1
    WHEN pl.plan_type_id IN (3, 4)
    THEN NOT EXISTS (SELECT 'X'
    FROM member_accounts ma
    member_enrollments men3
    plans pl3
    plan_types pt3
    WHERE ma.member_account_id = men3.member_account_id
    AND ma.employee_id = men2.employee_id
    AND nvl(ma.account_end_date, sysdate) <= trunc(sysdate)
    AND ma.plan_id = pl3.plan_id
    AND pl3.start_date <= pl2.START_DATE
    AND TRUNC(men3.coverage_effective_date) <> TRUNC(NVL(men3.coverage_end_date, men3.coverage_effective_date + 1 ))
    AND pl3.plan_type_id = pt3.plan_type_id
    AND pt3.plan_type_id in (3, 4)
    END
    AND (CASE WHEN pl.plan_type_id IN (1,2)
    ERROR at line 89:
    ORA-00936: missing expression

    Maybe
    SELECT ee.employee_id,
           'WELCOMEMSG',
           DECODE(me.member_enrollment_id,first_enr.enrollment_id,20,23) status_id,
           me.member_enrollment_id,
           wk.welcome_msg_id
      FROM wk,
           employees ee,
           MEMBER_ENROLLMENTS me,
           plans pl,
           (SELECT employee_id,
                   plan_type_id,
                   start_date,
                   plan_id,
                   MIN(MEMBER_ENROLLMENT_ID) member_enrollment_id
              FROM (SELECT me.employee_id,
                           DECODE(pl.plan_type_id,1,2,pl.plan_type_id) plan_type_id,
                           pl.start_date,
                           wk.plan_id,
                           me.member_enrollment_id
                      FROM wk,
                           PLANS pl,
                           MEMBER_ENROLLMENTS me
                     WHERE wk.done_by = nvl('TEST',wk.done_by)  /* same as wk.done_by = 'TEST' */
                       AND wk.welcome_msg_name 'NONE'
                       AND pl.employer_id = wk.employer_id
                       AND wk.employer_id = 5
                       AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
                       AND pl.plan_id = NVL(wk.plan_id,pl.plan_id)
                       AND me.plan_id = pl.plan_id
                       AND me.coverage_effective_date != NVL(me.coverage_end_Date,me.coverage_effective_date + 1)
                       AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date,me.coverage_effective_date + 1)
                    MINUS
                    SELECT me.employee_id,
                           DECODE(pl.plan_type_id,1,2,pl.plan_type_id) plan_type_id,
                           pl.start_date,
                           NULL plan_id,
                           me.member_enrollment_id
                      FROM wk,
                           PLANS pl,
                           MEMBER_ENROLLMENTS me
                     WHERE wk.done_by = nvl(NULL,wk.done_by)  /* same as 1 = 1 */
                       AND wk.welcome_msg_name 'NONE'
                       AND pl.employer_id = wk.employer_id
                       AND wk.employer_id = 5
                       AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
                       AND pl.plan_id = wk.plan_id
                       AND me.plan_id = pl.plan_id
                       AND me.coverage_effective_date NVL(me.coverage_end_Date,me.coverage_effective_date + 1)
                       AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
             WHERE employee_id = 100
             GROUP BY employee_id,
                      plan_type_id,
                      start_date,
                      plan_id
           ) first_enr,
           MEMBER_EVENTS mv
    WHERE wk.done_by = nvl(NULL,wk.done_by)
       AND wk.employer_id = ee.employer_id
       AND ee.employee_id = me.employee_id
       AND ee.employee_id = 100
       AND me.plan_id = pl.plan_id
       AND me.coverage_effective_date != NVL(me.coverage_end_Date,me.coverage_effective_date + 1)
       AND me.coverage_effective_Date BETWEEN wk.start_date AND NVL(wk.end_date, me.coverage_effective_date + 1)
       AND is_expired(me.employee_id,me.plan_id) = 'Y'
       AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = wk.plan_type_id
       AND pl.plan_id = nvl(wk.plan_id,pl.plan_id)
       AND me.employee_id = first_enr.employee_id
       AND DECODE(pl.plan_type_id,1,2,pl.plan_type_id) = first_enr.plan_type_id
       AND pl.start_date = first_enr.start_date
       AND me.member_enrollment_id = mv.member_enrollment_id(+)
       AND 'WELCOMEMSG' = mv.event_name(+)
       AND mv.member_enrollment_id IS NULL
       AND wk.welcome_msg_name != 'NONE'
       AND NVL(first_enr.plan_id,0) = NVL(wk.plan_id,0)
       AND (
            FN_get_all_participant(wk.employer_id) = 1
        OR
            (FN_get_all_participant(wk.employer_id) = 0
       AND   NOT EXISTS(SELECT 'X'
                          FROM member_accounts ma,
                               member_enrollments men3,
                               plans pl3,
                               plan_types pt3
                         WHERE ma.member_account_id = men3.member_account_id
                           AND ma.employee_id = me.employee_id
                           AND ma.plan_id = pl3.plan_id
                           AND pl3.start_date < pl.START_DATE
                           AND TRUNC(men3.coverage_effective_date) != TRUNC(NVL(men3.coverage_end_date,men3.coverage_effective_date + 1))
                           AND pl3.plan_type_id = pt3.plan_type_id
                           AND pt3.plan_type_id in (1,2)
                           and pl.plan_type_id IN (1,2)
                        UNION
                        SELECT 'X'
                          FROM member_accounts ma,
                               member_enrollments men3,
                               plans pl3,
                               plan_types pt3
                         WHERE ma.member_account_id = men3.member_account_id
                           AND ma.employee_id = me.employee_id
                           AND ma.plan_id = pl3.plan_id
                           AND pl3.start_date = (pl.start_date - 365)
                           AND TRUNC(men3.coverage_effective_date) != TRUNC(NVL(men3.coverage_end_date,men3.coverage_effective_date + 1))
                           AND pl3.plan_type_id = pt3.plan_type_id
                           AND pt3.plan_type_id = wk.plan_type_id
                           and pl.plan_type_id IN (1,2)
                        UNION
                        SELECT 'X'
                          FROM member_accounts ma,
                               member_enrollments men3,
                               plans pl3,
                               plan_types pt3
                         WHERE ma.member_account_id = men3.member_account_id
                           AND ma.employee_id = men2.employee_id
                           AND ma.plan_id = pl3.plan_id
                           AND pl3.start_date < pl2.START_DATE -- '01-Jan-2011'
                           AND TRUNC(men3.coverage_effective_date) != TRUNC(NVL(men3.coverage_end_date,men3.coverage_effective_date + 1))
                           AND pl3.plan_type_id = pt3.plan_type_id
                           AND pt3.plan_type_id = (1,2)
                           and pl.plan_type_id IN (1,2)
                        UNION
                        SELECT 'X'
                          FROM member_accounts ma,
                               member_enrollments men3,
                               plans pl3,
                               plan_types pt3
                         WHERE ma.member_account_id = men3.member_account_id
                           AND ma.employee_id = men2.employee_id
                           AND trunc(nvl(ma.account_end_date,sysdate)) <= trunc(sysdate)
                           AND ma.plan_id = pl3.plan_id
                           AND pl3.start_date <= pl2.START_DATE
                           AND TRUNC(men3.coverage_effective_date) != TRUNC(NVL(men3.coverage_end_date,men3.coverage_effective_date + 1))
                           AND pl3.plan_type_id = pt3.plan_type_id
                           AND pt3.plan_type_id in (3,4)
                           and pl.plan_type_id IN (3,4)
           )Regards
    Etbin

  • Need some help with a case statement implementation

    I am having trouble using a CASE statement to compare values and then display the results. The other issue is that i want to put these results in a separate column somehow.
    Heres how the code would look:
    SELECT "Task"."Code",
    "Stat" = CASE WHEN "Task.Code" = 1 THEN string
    ....and so on
    I wanted to make "Stat" the new column for the results, and string represents the string to be assigned if 1 was the value for code. I keep getting syntax error, any help would be nice.

    This is a lot easier than you might think.
    1) First, move another column of "Code" to your workspace.
    2) Click on the fx button and then on the BINS tab.
    3) Click on "Add BIN" and with the operand on "is equal to/is in," input 1 and then click "OK."
    4) Name this what you had for "string."
    Repeat for all the different values you want to rename as another "string" value.
    5) Finally, check the "custom heading" checkbox, and rename this column "Stat" as you indicated.
    That's it.

  • Help with Switch-Case Statement

    How do you get this in a switch-case statement or work with it?
              if (age < 70) {
                        JOptionPane.showMessageDialog(null, "People that are below the 70s are nothing special.");
              else if (age > 69 && age < 80) {
                        JOptionPane.showMessageDialog(null,  "People that are in their 70s are called septuagenarian.");
              else if (age > 79 && age < 90) {
                        JOptionPane.showMessageDialog(null,  "People that are in their 80s are called octogenarian.");
              else if (age > 89 && age < 100) {
                        JOptionPane.showMessageDialog(null,  "People that are in their 90s are called nonagenarian.");
              else (age > 99 && age < 110) {
                        JOptionPane.showMessageDialog(null,  "People that are in their 100s are called centenarian.");
                   }Thanks~

    As per Java Specification, swtich case expects an integer and boolean cannot be used as param for switch.
    In your case switch can be used like this.
    int index = age /10;
    switch(index) {
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    Your First case
    break;
    case 7:
    your second case
    break;
    case 8:
    third case
    break;
    case 9:
    fourth case
    break;
    default:
    fifth case
    break;
    Take note of the break statements. Its very important. But I wont prefer in this case. Code looks awkward and is not so meaningful.....

  • Need help to write case statement

    Hi Guys,
    I have dashboard in which its has pprompt called PROPMT1 in that prompt it has three values A,B,C
    but iwant the full abbreviation of those values like A=APPLE B=BOY and C=Cindy
    and also in the report i have the coloumn is prompted by PROMPT1 which has again A,B,C values that need to be modified as A=APPLE B=BOY and C=Cindy
    how can i do it with case statement.

    For the prompt, write this in the Show window>SQL Results:
    1) CASE WHEN 1=0 THEN char_columnname ELSE 'A = APPLE' END FROM "your subject area" UNION ALL CASE WHEN 1=0 THEN char_columnname ELSE 'B = BOY' END FROM "your subject area" UNION ALL CASE WHEN 1=0 THEN char_columnname ELSE 'C = Cindy' END FROM "your subject area"
    2) Save the prompt to a presentation variable, pv_choice
    This will give you your three values. Make sure you use a CHAR column, doesnt matter what column, though.
    For the report,
    1) Create a BINS column on the column that contains the A, B, C values and make the BINS A = APPLE, B = BOY, C = Cindy just like the prompt values.
    2) Now put a filter on this BINS column and set it equal to your pv_choice presentation variable.
    That's it.
    NOTE: Obviously, if you want the prompt values to just say "APPLE," "BOY," and "Cindy," then take off the 'A = ', 'B = ' and 'C = ' appropriately. Same for the BINS in your report.
    Edited by: David_T on Jun 8, 2011 10:57 AM

Maybe you are looking for

  • Windows Vista Issues?

    I just Installed windows Vista x64 and my iPod won't seem to connect... Windows recognizes it as an iPod at first but then installs USB mass storage drivers(i think).... still i don't see it in My Computer or Itunes, it DOES charges.. USB sticks DO w

  • XML parsing failed while select from my table with criteria

    While select from my table an error displayed as ORA-31011: XML parsing failed ORA-19202: Error occurred in XML processing LPX-00601: Invalid token in: '/<XML Path>/row[c24="SA0010001"]' select * from category where existsNode(xmlrecord, '/<XML Path>

  • ICloud Syncing issues on iOS7 on 5s?

    Since switching over to iOS7 and an iPhone 5s I am having the following issues: 1. All my keyboard shortcuts (which sync using icloud) are gone. 2. I cannot see any of my icloud documents in Pages, Numbers or Keynote on my iPhone? 3. If I make any ch

  • Archive Utility keeps jumping to front

    Wondering if there's a hidden pref to keep Archive Utility from displacing the current app when it automatically expands a download. This can be dangerous at times.

  • I cant install i tunes 10.7 because it says im not the administrator?

    i have suddenly been told that i cannot install i tunes 10.7 as im not the administrator , i am the only user on my laptop and have never had this issue with other i tunes software updates