Need help with special select case

Oracle DB 12c, I think 12.1.2
drop table person_tests;
create table person_tests (
person_id number,
test_type_id varchar2(1),
test_date date
insert into person_tests (person_id,test_type_id,test_date) values (1,'A',to_date('01012000','MMDDYYYY'));
insert into person_tests (person_id,test_type_id,test_date) values (1,'A',to_date('01022000','MMDDYYYY'));
insert into person_tests (person_id,test_type_id,test_date) values (1,'B',to_date('01032000','MMDDYYYY'));
insert into person_tests (person_id,test_type_id,test_date) values (1,'B',to_date('01042000','MMDDYYYY'));
insert into person_tests (person_id,test_type_id,test_date) values (1,'C',to_date('01052000','MMDDYYYY'));
insert into person_tests (person_id,test_type_id,test_date) values (2,'C',to_date('01062000','MMDDYYYY'));
insert into person_tests (person_id,test_type_id,test_date) values (3,'A',to_date('01072001','MMDDYYYY'));
insert into person_tests (person_id,test_type_id,test_date) values (3,'A',to_date('01082000','MMDDYYYY'));
insert into person_tests (person_id,test_type_id,test_date) values (3,'B',to_date('01092000','MMDDYYYY'));
insert into person_tests (person_id,test_type_id,test_date) values (3,'B',to_date('01102000','MMDDYYYY'));
insert into person_tests (person_id,test_type_id,test_date) values (3,'C',to_date('01102000','MMDDYYYY'));
Persons as participating in certain tests: A, B and C where each test is tagged with a date when done.
I need to output only people that completed 2 tests of type A, 2 tests of type B and 1 test of type C. I have to display the test type and the date of the most recent of those tests. In the example above, desired output would be
1 C            05-JAN-00
3 A            07-JAN-01
Hope this problem definition makes sense

Hi,
Sorry, I missed the requirement about showing the most recent test_type_id.
Assuming the date to be shown is the date the minimum requirements were fulfilled (whether of not gratutitous tests came afterwrds), you can do something like this:
WITH    got_r_num    AS
    SELECT  person_id, test_type_id, test_date
    ,       ROW_NUMBER () OVER ( PARTITION BY  person_id, test_type_id
                                 ORDER BY      test_date
                               )   AS r_num
    FROM    person_tests
    WHERE   test_type_id  IN ('A', 'B', 'C')
SELECT    person_id
,         MIN (test_type_id) KEEP (DENSE_RANK LAST ORDER BY  test_date)  AS last_test_type
,         MAX (test_date)                                                AS last_test_date
FROM      got_r_num
WHERE     r_num  <= CASE  test_type_id
                        WHEN  'A'  THEN  2
                        WHEN  'B'  THEN  2
                        WHEN  'C'  THEN  1
                    END
GROUP BY  person_id
HAVING    COUNT (*)  = 5  -- 2 'A's  +  2 'B's  +  1 'C'
What test_type_id would you want to display in case of a tie for the latest test?
I just saw your post saying that a person with 3 or more type 'A' tests should be excluded.  In that case, my original solution (with = in the main WHERE clause) is what you want; only used LAST to get the latest test_type_id.  The solution in this message is for the situation where you don't care if someone had 3 or more 'A's, but you want to ignore all but the first 2.

Similar Messages

  • I need help with a SELECT query - help!

    Hello, I need help with a select statement.
    I have a table with 2 fields as shown below
    Name | Type
    John | 1
    John | 2
    John | 3
    Paul | 1
    Paul | 2
    Paul | 3
    Mark | 1
    Mark | 2
    I need a query that returns everything where the name has type 1 or 2 but not type 3. So in the example above the qery should bring back all the "Mark" records.
    Thanks,
    Ian

    Or, if the types are sequential from 1 upwards you could simply do:-
    SQL> create table t as
      2  select 'John' as name, 1 as type from dual union
      3  select 'John',2 from dual union
      4  select 'John',3 from dual union
      5  select 'Paul',1 from dual union
      6  select 'Paul',2 from dual union
      7  select 'Paul',3 from dual union
      8  select 'Paul',4 from dual union
      9  select 'Mark',1 from dual union
    10  select 'Mark',2 from dual;
    Table created.
    SQL> select name
      2  from t
      3  group by name
      4  having count(*) <= 2;
    NAME
    Mark
    SQL>Or another alternative if they aren't sequential:
    SQL> ed
    Wrote file afiedt.buf
      1  select name from (
      2    select name, max(type) t
      3    from t
      4    group by name
      5    )
      6* where t < 3
    SQL> /
    NAME
    Mark
    SQL>Message was edited by:
    blushadow

  • Need help with db select

    As usual I have been stuck for a while on what is probably a very simple solution so perhaps someone can help me, thanks.
    I have a portfolio page to which I post a url to filter the portfolio type (0, 1 or 2) and display the results.
    It works ok except that I can't get the url right to show all records. I have tried things like
    /portfolio.php?websitetype=1&2
    and
    /portfolio.php?websitetype=*
    /portfolio.php?websitetype>0
    Perhaps I need to change my select?
    $query_portfolio = "SELECT * FROM portfoliodb WHERE portfoliodb.websitetype='". $_GET['websitetype'] ."'  AND portfoliodb.visible = 1 ORDER BY portfoliodb.portfolio_id DESC";

    bikeman01 wrote:
    Ok I've now got it working as suggested so that's a big improvement, thanks but it's not quite what I was after. What I want is for all records to be retrieved by default when there is no url suffix and not require ?websitetype=ALL
    That is not what your OP asked for!
    It works ok except that I can't get the url right to show all records. I have tried things like
    /portfolio.php?websitetype=1&2
    and
    /portfolio.php?websitetype=*
    /portfolio.php?websitetype>0
    // determine if the URL parameter for websitetype is set.
    if (isset($_GET['websitetype'])) {
                   // run a query to filter only selected types
                   // based off value of URL parameter
                        $query_portfolio = "SELECT *
                        FROM portfoliodb
                        WHERE portfoliodb.websitetype='". $_GET['websitetype'] ."'
                        AND portfoliodb.visible = 1
                        ORDER BY portfoliodb.portfolio_id DESC";
    // else if the URL parameter for websitetype is not set.
    } else {
                        //  run query to display ALL types
                        $query_portfolio = "SELECT *
                        FROM portfoliodb
                        ORDER BY portfoliodb.portfolio_id DESC";
    // end condition if the URL parameter for websitetype is set.

  • Need help with special logic...

    Hi,
    i have a query which selects all status changes for tasks. For every NEW status a record is inserted where the new status TYPE and ENTRY_DATE are stored.
    A task can have several statuses based on this information (unlimited number of status changes is allowed):
    1.) Open (the last inserted status record has type: 'Open')
    2.) Closed (the last inserted status record has type 'Closed')
    I need to get the following result:
    TASK_ID     START_TIME        STOP_TIME          
    333450      09-01-09 10:00     09-01-09 11:00    
    333450      12-01-09 10:00     12-01-09 15:00    
    333450      12-01-09 16:00     12-01-09 16:00    
    333450      12-01-09 16:00     CURRENT_DATE    
    Scenarios:
    - Multiple 'Close' records after each other: The START_TIME in the 3d tuple should be copied from the STOP_TIME in the real data.
    - No 'Close' record: The STOP_TIME in the 4th tuple should be the CURRENT_DATE.
    - Multiple 'Open' records after each other: The STOP_TIME of the previous 'Open' record in the realdata should be the ENTRY_DATE of the 'current' record in the realdata. (THIS ONE ISN'T PRESENT IN THE DATA EXAMPLE!!!)
    From this data:
    with REALDATA as (
    select 104993 PLAN_ID, to_date('09-01-09 10:00','dd-MM-yy HH24:MI') ENTRY_DATE, 'Open' STATUS_DESCRIPTION, 'Open' STATUS_TYPE, 333450 TASK_ID, 'Assembly' TASK_DESCRIPTION from dual
    union
    select 104993, to_date('09-01-09 11:00','dd-MM-yy HH24:MI'), 'Completed', 'Closed', 333450, 'Assembly' from dual
    union
    select 104993, to_date('12-01-09 10:00','dd-MM-yy HH24:MI'), 'Open', 'Open', 333450, 'Assembly' from dual
    union
    select 104993, to_date('12-01-09 15:00','dd-MM-yy HH24:MI'), 'Completed', 'Closed', 333450, 'Assembly' from dual
    union
    select 104993, to_date('12-01-09 16:00','dd-MM-yy HH24:MI'), 'Completed', 'Closed', 333450, 'Assembly' from dual
    union
    select 104993, to_date('13-01-09 15:00','dd-MM-yy HH24:MI'), 'Open', 'Open', 333450, 'Assembly' from dual
    select TASK_ID, TO_CHAR(ENTRY_DATE,'dd-MM-yy HH24:MI'), STATUS_DESCRIPTION, STATUS_TYPE, TASK_DESCRIPTION from realdata order by ENTRY_DATE
    Extra abstraction:_
    So the data should be sorted by ENTRY_DATE:
    then it should be 'grouped' like this (very abstract: tuples split by comma, between (brackets) is which ENTRY_DATE the data should come from)):
    - normal pair
    OPEN, CLOSED
    result: START_TIME (OPEN) | STOP_TIME (CLOSED)
    - multiple open records
    OPEN, OPEN, OPEN, CLOSED
    result: START_TIME (OPEN) | STOP_TIME (next OPEN), START_TIME (OPEN) | STOP_TIME (next OPEN), START_TIME (OPEN) | STOP_TIME (CLOSED)
    - multiple closed records
    OPEN, CLOSED, CLOSED
    result: START_TIME (OPEN) | STOP_TIME (CLOSED), START_TIME (CLOSED) | STOP_TIME (CLOSED)
    - no open record
    CLOSED[,CLOSED]
    result: START_TIME (CLOSED) | STOP_TIME (CLOSED)[,START_TIME (CLOSED) | STOP_TIME (CLOSED)]
    - no closed record
    OPEN
    result: START_TIME (OPEN) | STOP_TIME (CURRENT_DATE)
    - no closed record with multiple open records
    OPEN, OPEN
    result: START_TIME (OPEN) | STOP_TIME (next OPEN), START_TIME (OPEN) | STOP_TIME (CURRENT_DATE)Edited by: user574699 on Jan 14, 2009 5:09 AM
    Edited by: user574699 on Jan 14, 2009 5:30 AM - Extra abstraction at the bottom!

    Based on your original data, I'd go with something like:
    with REALDATA as (select 104993 PLAN_ID, to_date('09-01-09 10:00','dd-MM-yy HH24:MI') ENTRY_DATE, 'Open' STATUS_DESCRIPTION, 'Open' STATUS_TYPE, 333450 TASK_ID, 'Assembly' TASK_DESCRIPTION from dual
                      union all
                      select 104993, to_date('09-01-09 11:00','dd-MM-yy HH24:MI'), 'Completed', 'Closed', 333450, 'Assembly' from dual
                      union all
                      select 104993, to_date('12-01-09 10:00','dd-MM-yy HH24:MI'), 'Open', 'Open', 333450, 'Assembly' from dual
                      union all
                      select 104993, to_date('12-01-09 15:00','dd-MM-yy HH24:MI'), 'Completed', 'Closed', 333450, 'Assembly' from dual
                      union all
                      select 104993, to_date('12-01-09 16:00','dd-MM-yy HH24:MI'), 'Completed', 'Closed', 333450, 'Assembly' from dual
                      union all
                      select 104993, to_date('13-01-09 15:00','dd-MM-yy HH24:MI'), 'Open', 'Open', 333450, 'Assembly' from dual),
       trans_data as (select task_id,
                             task_description,
                             plan_id,
                             entry_date,
                             nvl(lead(entry_date) over (partition by task_id, task_description, plan_id
                                                        order by entry_date), sysdate) stop_date,
                             status_type status,
                             lag(status_type) over (partition by task_id, task_description, plan_id
                                                    order by entry_date) prev_status,
                             lead(status_type) over (partition by task_id, task_description, plan_id
                                                     order by entry_date) next_status
                      from   realdata)
    select task_id,
           task_description,
           plan_id,
           entry_date,
           case when status = 'Closed' and next_status != 'Closed' then
                     entry_date
                else stop_date
           end
    from   trans_data
    where  case when status = 'Closed' and prev_status = 'Open' then
                     1
                else 0
           end != 1But it looks like your actual data is more complicated than the original set of data (extra statuses for one). Also, you haven't said what should happen (I don't think) in the case of "Open, Close, Open Close" - I've taken it that the 2nd Open should have a start time of the 2nd Open, rather than the stop time of the 1st close.

  • Need Help With A Select Staement

    This is my data set.
    OPEN_DATE CLOSE_DATE
    02-JAN-08 02-JAN-08
    02-JAN-08 02-JAN-08
    02-JAN-08 02-JAN-08
    02-JAN-08 03-JAN-08
    04-JAN-08 04-JAN-08
    05-JAN-08
    07-JAN-08
    07-JAN-08 07-JAN-08
    07-JAN-08 07-JAN-08
    08-JAN-08 08-JAN-08
    08-JAN-08
    02-JAN-08
    02-JAN-08
    08-JAN-08
    09-JAN-08
    I'm need totals for those that are opened and closed per day. Here is what I'm trying to achieve...
    Status Value DATE
    Open 6 02-JAN-08
    Closed 3 02-JAN-08
    Open 0 03-JAN-08
    Closed 1 03-JAN-08
    Open 1 04-JAN-08
    Closed 1 04-JAN-08
    Open 0 05-JAN-08
    Closed 1 05-JAN-08
    Open 3 07-JAN-08
    Closed 2 07-JAN-08
    Open 3 08-JAN-08
    Closed 1 08-JAN-08
    Open 1 09-JAN-08
    Close 0 09-JAN-08
    This select statement gets me close but the problem is how to get the ones that should have a Value of 0
    select 'Open' "Status", count(*) "Value", to_char(open_date, 'DD-MON-YY') "DATE"
    from usar_log2
    where open_date IS NOT NULL and
    to_char(open_date, 'MON-YY') = to_char(sysdate, 'MON-YY')
    and (USAR_status like 'CLOSED' or usar_status like 'OPENED' or USAR_Status like 'WORKING')
    group by to_char(open_date, 'DD-MON-YY')
    UNION
    select 'Closed' "status", count(*) "Close", to_char(close_date, 'DD-MON-YY')
    from usar_log2
    where close_date is not null and
    to_char(close_date, 'MON-YY') = to_char(sysdate, 'MON-YY')
    and (USAR_status like 'CLOSED' or usar_status like 'OPENED' or USAR_Status like 'WORKING')
    group by to_char(close_date, 'DD-MON-YY')
    order by 3, 1 desc;
    The above select statement's results...
    Status Value DATE
    Open 6 02-JAN-08
    Closed 3 02-JAN-08
    Closed 1 03-JAN-08
    Open 1 04-JAN-08
    Closed 1 04-JAN-08
    Closed 1 05-JAN-08
    Open 3 07-JAN-08
    Closed 2 07-JAN-08
    Open 3 08-JAN-08
    Closed 1 08-JAN-08
    Open 1 09-JAN-08
    But I need this instead...
    Status Value DATE
    Open 6 02-JAN-08
    Closed 3 02-JAN-08
    <----- Open 0 03-JAN-08
    Closed 1 03-JAN-08
    Open 1 04-JAN-08
    Closed 1 04-JAN-08
    <----- Open 0 05-JAN-08
    Closed 1 05-JAN-08
    Open 3 07-JAN-08
    Closed 2 07-JAN-08
    Open 3 08-JAN-08
    Closed 1 08-JAN-08
    Open 1 09-JAN-08
    <----- Close 0 09-JAN-08
    Any help would be more appreciative.

    Thank you...You all are great. While I'm still
    looking at the various ways you all provided, from
    what I have looked at so far, they don't address
    05-JAN-08 which has a null open date. There are
    three possiblities, maybe four. Does 05-JAN-08 have a null open date in the data you supplied?
    You showed us:
    OPEN_DATE CLOSE_DATE
    02-JAN-08 02-JAN-08
    02-JAN-08 02-JAN-08
    02-JAN-08 02-JAN-08
    02-JAN-08 03-JAN-08
    04-JAN-08 04-JAN-08
    05-JAN-08
    07-JAN-08
    07-JAN-08 07-JAN-08
    07-JAN-08 07-JAN-08
    08-JAN-08 08-JAN-08
    08-JAN-08
    02-JAN-08
    02-JAN-08
    08-JAN-08
    09-JAN-08
    which looks like they all have open dates.
    Perhaps, if there was null open dates you should have used [code][/code] or [pre][/pre] tags around your data so it looked something like
    OPEN_DATE CLOSE_DATE
    02-JAN-08 02-JAN-08
    02-JAN-08 02-JAN-08
    02-JAN-08 02-JAN-08
    02-JAN-08 03-JAN-08
    04-JAN-08 04-JAN-08
              05-JAN-08
    07-JAN-08
    07-JAN-08 07-JAN-08
    07-JAN-08 07-JAN-08
    08-JAN-08 08-JAN-08
    08-JAN-08
    02-JAN-08
    02-JAN-08
    08-JAN-08
    09-JAN-08And then it would have required the ANSI outer join in my query to allow for outer joining on more than one column...
    SQL> ed
    Wrote file afiedt.buf
      1  WITH t as (SELECT to_date('02-JAN-2008','DD-MON-YYYY') as open_date, to_date('02-JAN-2008','DD-MON-YYYY') as closed_date from dual union all
      2             SELECT to_date('02-JAN-2008','DD-MON-YYYY'), to_date('02-JAN-2008','DD-MON-YYYY') from dual union all
      3             SELECT to_date('02-JAN-2008','DD-MON-YYYY'), to_date('02-JAN-2008','DD-MON-YYYY') from dual union all
      4             SELECT to_date('02-JAN-2008','DD-MON-YYYY'), to_date('03-JAN-2008','DD-MON-YYYY') from dual union all
      5             SELECT to_date('04-JAN-2008','DD-MON-YYYY'), to_date('04-JAN-2008','DD-MON-YYYY') from dual union all
      6             SELECT NULL, to_date('05-JAN-2008','DD-MON-YYYY') from dual union all
      7             SELECT to_date('07-JAN-2008','DD-MON-YYYY'), NULL from dual union all
      8             SELECT to_date('07-JAN-2008','DD-MON-YYYY'), to_date('07-JAN-2008','DD-MON-YYYY') from dual union all
      9             SELECT to_date('07-JAN-2008','DD-MON-YYYY'), to_date('07-JAN-2008','DD-MON-YYYY') from dual union all
    10             SELECT to_date('08-JAN-2008','DD-MON-YYYY'), to_date('08-JAN-2008','DD-MON-YYYY') from dual union all
    11             SELECT to_date('08-JAN-2008','DD-MON-YYYY'), NULL from dual union all
    12             SELECT to_date('02-JAN-2008','DD-MON-YYYY'), NULL from dual union all
    13             SELECT to_date('02-JAN-2008','DD-MON-YYYY'), NULL from dual union all
    14             SELECT to_date('08-JAN-2008','DD-MON-YYYY'), NULL from dual union all
    15             SELECT to_date('09-JAN-2008','DD-MON-YYYY'), NULL from dual)
    16      ,all_dates as (select minod+rownum-1 as dt
    17                     from   dual, (select min(open_date) minod, max(open_date) maxod from t)
    18                     connect by rownum <= maxod-minod+1)
    19      ,stat as (select 'open' as status from dual union all select 'closed' from dual)
    20  -- END OF DATA
    21  select all_dates.dt, stat.status, sum(decode(decode(stat.status, 'open', t.open_date, t.closed_date), all_dates.dt, 1, 0)) as cnt
    22  from   stat JOIN all_dates ON (1=1)
    23         LEFT OUTER JOIN t ON (NVL(t.open_date, NVL(t.closed_date, all_dates.dt)) = all_dates.dt)
    24  group by all_dates.dt, stat.status
    25* order by 1,2 desc
    SQL> /
    DT        STATUS        CNT
    02-JAN-08 open            6
    02-JAN-08 closed          3
    03-JAN-08 open            0
    03-JAN-08 closed          0
    04-JAN-08 open            1
    04-JAN-08 closed          1
    05-JAN-08 open            0
    05-JAN-08 closed          1
    06-JAN-08 open            0
    06-JAN-08 closed          0
    07-JAN-08 open            3
    07-JAN-08 closed          2
    08-JAN-08 open            3
    08-JAN-08 closed          1
    09-JAN-08 open            1
    09-JAN-08 closed          0
    16 rows selected.
    SQL>Make your requirements clear in the future.

  • Help with error select case statement (ORA-00932: inconsistent datatypes)

    Hi,
    I'm struggling to get my sql query work on Oracle..
    I have a table MyTable with 5 columns ( Column1, Column2, Column3, Column4, Column5 ) all are of type NVARCHAR2.
    I need to check whether Column 3, Column 4 are empty or not in that order..and if they values then I wanna append it to Column2.
    For example
    If a row contains the following values,
    Column 2 = a.b
    Column 3 = 123
    Column 4 = xyz
    then column CA = a.b/123/xyz where column CA = temp column
    If either Column 3 or Column 4 is empty/null, then I don't need to append value for that column..
    For example
    Column 2 = a.b
    Column 3 = either NULL or ''
    Column 4 = xyz
    then CA = a.b/xyz where column CA = temp column
    similarly..
    Column 2 = a.b
    Column 3 = 123
    Column 4 = either NULL or ''
    then CA = a.b/123 where column CA = temp column
    Here is my query..
    select MyTable.Column1 as CA0,
    MyTable.Column2 as CA1,
    MyTable.Column3 as CA2,
    MyTable.Column4 as CA3,
    MyTable.Column5 as CA4,
    MyTable.Column2 + CASE WHEN MyTable.Column3 > '' THEN '/' + MyTable.Column3 ELSE '' END + CASE WHEN MyTable.Column4 > '' THEN '/' + MyTable.Column4 ELSE '' END CA
    from MyTable;
    This query works just fine against SQL Server db, but gainst Oracle I'm getting
    ORA-00932: inconsistent datatypes: expected NUMBER got CHAR
    00932. 00000 - "inconsistent datatypes: expected %s got %s"
    Could you please let me know what I'm doing wrong. I need to get this query working on both SQL Server and Oracle..
    Please let me know your suggestions and thoughts..
    Cheers,

    I need to check whether Column 3, Column 4 are empty or not in that order..and if they values then I wanna append it to Column2. In Oracle, you can do it this way - no need to do all kinds of difficult things:
    select col2||col3||col4
      from tbl

  • Need help with changing letter cases : (

    Hey everyone, I have an assignment that needs to
    1) allow the user to enter a sentence
    2) count the number of upper case, lower case, spaces, and other characters in the sentence,
    3) convert each first letter of a word into upper case if not already in upper case,
    4) convert non first letters to lower case if not already in lower case
    So, I have been successfull counting all characters, but I can't seem to find a way to convert the letter cases.
    I understand I have to distinguish first letters and non first letters, and I did this by using a boolean.
    Also, I tried to use a for loop and convert the letter cases accordingly by += 32 and -= 32.
    This is what I have for now :
    import javax.swing.JOptionPane;
    public class Asg3 {
         public static void main(String [] args)     {
              String sentence = JOptionPane.showInputDialog("Enter a Sentence!");
              int length = sentence.length();
              int counter = 0;
              int uppercase = 0;
              int lowercase = 0;
              int space = 0;          
              int other = 0;
              int total = 0;
              boolean firstletter = true;
              char thischarac;
              for (counter = 0; counter < sentence.length(); counter++)
                        thischarac = sentence.charAt(counter);
                        if ( thischarac >= 65 && thischarac <= 90 ) {
                             ++ uppercase;
                   else if ( thischarac >= 97 && thischarac <= 122 ) {
                             ++ lowercase;
                   else if ( thischarac == 32) {
                             ++ space;
                   else {
                             ++ other;
                             ++ total;
              for (counter = 0; counter < sentence.length(); counter++) {
                   thischarac = sentence.charAt(counter);
                   if (firstletter == true) {
                             if (thischarac >= 97 && thischarac <= 122) {
                                  thischarac -= 32;
                   else
                        if (firstletter == false)
                             if (thischarac >= 65 && thischarac <= 90) {
                                  thischarac += 32;
    System.out.println("You have entered: " + sentence);
              System.out.println("Upper case Letters: " + uppercase);
              System.out.println("Lower case Letters: " + lowercase);
              System.out.println("The number of blank spaces: " + space);
              System.out.println("The number of other characters: " + other);
              System.out.println("Grand total: " + total);
              System.exit( 0 );               
    I am stuck on this for hours now, and all googling, asking friends, going over lectures have failed, and this is my last resort.
    I understand it is frustrating when students come here for homework, but I would really appreciate any hints or help.
    Thank you!

    Oh, sorry I'm new and didn't realize the code button. Anyways, here it is
    import javax.swing.JOptionPane;
    public class Asg3 {
         public static void main(String [] args)     {
              String sentence = JOptionPane.showInputDialog("Enter a Sentence!");
              int length = sentence.length();
              int counter = 0;
              int uppercase = 0;
              int lowercase = 0;
              int space = 0;          
              int other = 0;
              int total = 0;
              boolean firstletter = true;
              char thischarac;
              for (counter = 0; counter < sentence.length(); counter++)
                        thischarac = sentence.charAt(counter);
                        if ( thischarac >= 65 && thischarac <= 90 ) {
                             ++ uppercase;
                   else if ( thischarac >= 97 && thischarac <= 122 ) {
                             ++ lowercase;
                   else if ( thischarac == 32) {
                             ++ space;
                   else {
                             ++ other;
                             ++ total;
              for (counter = 0; counter < sentence.length(); counter++) {
                   thischarac = sentence.charAt(counter);
                   if (firstletter == true) {
                             if (thischarac >= 97 && thischarac <= 122) {
                                  thischarac -= 32;
                   else
                        if (firstletter == false)
                             if (thischarac >= 65 && thischarac <= 90) {
                                  thischarac += 32;
                                    System.out.println("You have entered: " + sentence);
              System.out.println("Upper case Letters: " + uppercase);
              System.out.println("Lower case Letters: " + lowercase);
              System.out.println("The number of blank spaces: " + space);
              System.out.println("The number of other characters: " + other);
              System.out.println("Grand total: " + total);
              System.exit( 0 );               
    }The problem I'm having is converting letters to their right cases. I need to change the first letters of a word to upper cases, and non first letters to lower cases. For example, if the sentence the user entered is
    "tHIS AssigNMent IS harD!" , I would have to convert it to : "This Assignment Is Hard!"
    What I tried to do is use a for loop and a boolean.
    If firstletter == true, and if the character was lower case, I would subtract 32 from that character.
    If firstletter == false, and if the character was upper case, I would add 32.
    The problem here is that, what do I have to do to make it print the converted sentence? I have tried System.out.println( "The new sentence is :" + sentence); which gives me only the original sentence,
    and System.out.println("The new sentence is :" + thiscarac); which gives me all capital letters.
    So there are two main problems:
    1) Is my forloop and boolean correct in converting the cases? Am I using the right method?
    2) If so, how do I get the system to printout the new converted sentence?
    Edited by: ShaRpy on Oct 28, 2008 4:51 PM

  • Need help with cursor selection in control panels

    I can't get my cursor to work in the control panel at the top of the screen, for example, when I select text and want to change the font size, etc.  It won't even select to change from font to paragraph mode.  Other issues are trying to choose the selection tool, which I can only do with the "V" shortcut tool--escape doesn't work, nor does the cursor choose the  icons.  Help!

    Windows? see InDesign tools and panels don't respond to mouse clicks (Windows 7/Vista)

  • Need help with Advanced Selection in MSA

    Hi,
    Has anyone managed to identify how to create additional
    advanced selection criteria using links to existing combo engines ? Documentation on Mobile system maint is limited so looking for some additional help. Some criteria you can run the check against but not all why ? What should go in the hierachy fields and how do you select the choice list values ?
    Thanks in advance
    M

    Hi,
    Thanks,my issue is I want to use the combo box so the user can select from the drop down the relevant code from the choice list. Not rocket science really.
    Example of sql generated for profession whch is kna1 field.
    select  KNA1.TITLE,KNA1.SFAKNA2,KNA1.SFAKNA1,KNA1.PROFRESSION as PROFESSION,KNA1.PAFKT,KNA1.NAME2,KNA1.NAME1,KNA1.KVTGRP,KNA1.KVCPPOS,KNA1.KUNNR,KNA1.KTOKD,KNA1.BPACT,KNA1.ANRED,KNA1.ABTNR,ADRC.TELNR_LONG,ADRC.STREET,ADRC.POST_CODE1,ADRC.CITY1,ADRC.ADRCDFLT,ADDR.SFAKNBP , (KNA1.PROFESSION ='MIC') as ReturnValue1 from SMOKNA1 KNA1,SMOADRC ADRC,CDBD_ADDREXT ADDR where kna1.deleted='0' and KNA1.Source='CON' and ADRC.deleted='0' and ADDR.deleted = '0' and (ADRC.ADRCDFLT='S' or ADRC.ADRCDFLT='P') and (1=1) and kna1.sfakna1=adrc.sfakna1 and adrc.sfaadrc = addr.sfaadrc order by kna1.name1
    Code fails !
    I have set VAR1 as a free Combo with Bdoc as Choice, segment as Choice List with fields chkey/Textx so hiearchy fields looks like this //*/Profession hiearchy params being mandt/spras/list
    It will not check is this because there is an error in this definition ?
    Regards
    MM

  • Need help with a SELECT statement

    Dear forumers,
    I'm a newbie in ABAP and I'm trying to figure out what the following line means (in bold letters):-
    SELECT SINGLE STAT2 FROM PA0000 INTO PA0000-STAT2
    WHERE PERNR = ITAB_DATA-STAFF_NO.
    Does this mean that the single data from the STAT2 field is selected and then placed back into the same field (doesn't quite makes sense, right)?
    Please help and many thanks in advance!

    SELECT SINGLE STAT2 FROM PA0000 INTO PA0000-STAT2
    WHERE PERNR = ITAB_DATA-STAFF_NO.
    Does this mean that the single data from the STAT2 field is selected and then placed back into the same field (doesn't quite makes sense, right)?
    it sense very much right.
    have you heared about table buffer concept?
    here this concept exactly comes.
    try with this below code:
    TABLES:pa0000."tables must be decleare
    SELECT SINGLE STAT2 FROM PA0000 INTO PA0000-STAT2.
      write:PA0000-STAT2.
    and since you are using select single than you should be use much key as much possible for getting accurate data.other wise system will pick first data which match your where condition.
    Amit.

  • PSE8 - Need help with bizarre selection problem with spot healing and clone tools

    In using clone stamp and spot healing brush--. When I Alt click for my sample I get entire image---acting as if I'm moving a layer---whether I'm working on a single or multi-layer image.  This is PSE8 3 gig ram windows ----Lenovo Core II duo  P8400  @ 2.26 GHZ  with ATI 256 meg graphics
    This sure is fun!!!
    I'm trying to get rid of an old numbering imprint on a film(not digital) image.

    Actually the overlay option is helpful. It shows the region that you are copying - and i dont think thats causing the issue.
    The issue is because you dont have the clip option checked along with Overlay.
    Just make sure you have both Overlay and Clipped options checked and you would not see this problem anymore.
    Regards,
    Pri
    (Attached an image of the settings)

  • Need help with Hierarchical Select List

    I'm trying to left-pad the entries in a select list to indicate organizational hierarchy. Here's the query:
    SELECT
    LPAD(' ',2*(LEVEL-1)) || ORG_NM d,
    ORG_ID r
    FROM
    ORG_ENTITIES
    START WITH ORG_ID = 901
    CONNECT BY PRIOR ORG_ID = MNG_ORG_ID
    ORDER BY 2;
    (there are two spaces between the single quotes)
    It seems to work fine from a standard SQL prompt, but it looks as if either Apex or the browser is stripping off the spaces in the padding. Can someone point out a reason? I'm using Application Express 3.0.0.00.20. Thanks.

    I've used the concatenation of two items to create space between them before, and that works fine. This is an LPAD situation, however, as there is only one item.
    I did try the & nbsp; in place of the literal space character. The select list strips out the & and I get some variation of the literal characters. I even tried using periods in place of spaces for the padding and that didn't work either.
    Don't know what is going on.

  • Need help with 'Video' selection on iPod

    I have a 30g iPod 5th generation, and I try to download some videos, but when I try to watch them on my iPod, they just play the sound, and don't show the video screen. They are in the mp4 format, if that is the problem. If anyone knows what the problem is, please help me.
    Thanks so much

    Does this article contain anything useful?
    (28691)

  • Need help with using selected class with includes...

    Hi guys,
    I'm using PHP includes for my site and in the header include I have my main navigation - so it's drawn in to whatever page the user goes to from header.php.
    I want to have a 'selected' <li> class for the navigation so the relevant button is highlighted depending on which page/section the user is on...
    How would I go about implementing it into header.php - is there a way I can put a bit of PHP in each of the pages to make the appropiate <li> in header.php use the 'selected' class?
    Thank you and I hope to hear from you.
    SM

    I'm sure there will be an easier way than this for PHP but if you give each menu item a class, you can then give each <body> a different id (or class) to determine where the user is.
    Eg:
    CSS
    nav li.menu_home a{style here} /* class is 'menu_home' for home menu item */
    #home nav li.menu_home a{style here} /* the id of 'home' is added to the body tag on the home page, <body id="home"> */
    HTML
    <body id="home">
    <!-- navigation include -->
    <nav>
    <ul>
    <li class="menu_home"><a href="">Home</a></li>
    </ul>
    </nav>
    <!-- end navigation include -->
    </body>
    Or you could try searching for a javascript method.

  • Need some help with the Select query.

    Need some help with the Select query.
    I had created a Z table with the following fields :
    ZADS :
    MANDT
    VKORG
    ABGRU.
    I had written a select query as below :
    select single vkorg abgru from ZADS into it_rej.
    IT_REJ is a Work area:
    DATA : BEGIN OF IT_REJ,
            VKORG TYPE VBAK-VKORG,
            ABGRU TYPE VBAP-ABGRU,
           END OF IT_REJ.
    This is causing performance issue. They are asking me to include the where condition for this select query.
    What should be my select query here?
    Please suggest....
    Any suggestion will be apprecaiated!
    Regards,
    Developer

    Hello Everybody!
    Thank you for all your response!
    I had changes this work area into Internal table and changed the select query. PLease let me know if this causes any performance issues?
    I had created a Z table with the following fields :
    ZADS :
    MANDT
    VKORG
    ABGRU.
    I had written a select query as below :
    I had removed the select single and insted of using the Structure it_rej, I had changed it into Internal table 
    select vkorg abgru from ZADS into it_rej.
    Earlier :
    IT_REJ is a Work area:
    DATA : BEGIN OF IT_REJ,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    Now :
    DATA : BEGIN OF IT_REJ occurs 0,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    I guess this will fix the issue correct?
    PLease suggest!
    Regards,
    Developer.

Maybe you are looking for

  • Looking for a music player app for the ipad

    Musician looking for music player app to play my sound library Folders, set lists......ect..... Must be able to automatically pause between songs, not like iTunes where you have to manually pause I have to time to manually pause between tracks since

  • Incorrect delivery creation date in stock transport order

    Hi, I've checked SAP notes and forums but no answers to this one....hope you can help. I have 2 plants, in separate company codes.  One orders from the other using a full inter-company process. The issue is, when i raise a PO the delivery date (shipp

  • Problem with SAX parser with String format

    hi, all I have the next problem: I try to parse xml file with success, I write next code: ==================== my_class saxUms = new my_class(); File file = new File( "c:\\my_try_Response.xml" ); InputSource src1 = new InputSource( new FileInputStrea

  • CTBW - SD Characteristics

    Hi Gurus We have a requirement to report on SD characteristics using transaction CTBW in R/3. We followed the steps in SAP Note 306046 and everything worked perfectly up to the point where we need to load the data into the newly created InfoObjects.

  • How to Add Entry into T530 and T530T?

    Anyone knows?