Query doubt

Dear Masters,
I have table called price detail with the following structure (with some sample rows)
with price_detail
as
select to_date('1/1/2013' , 'mm/dd/yyyy') sell_date, 100 dealer_price, 10 discount from dual
union all
select to_date('1/2/2013' , 'mm/dd/yyyy') sell_date, 120 dealer_price, 20 discount from dual
union all
select to_date('1/3/2013' , 'mm/dd/yyyy') sell_date, 200 dealer_price, 10 discount from dual
union all
select to_date('1/4/2013' , 'mm/dd/yyyy') sell_date, 100 dealer_price, 20 discount from dual
union all
select to_date('1/5/2013' , 'mm/dd/yyyy') sell_date, 120 dealer_price, 10 discount from dual
union all
select to_date('1/6/2013' , 'mm/dd/yyyy') sell_date, 210 dealer_price, 30 discount from dual
union all
select to_date('1/7/2013' , 'mm/dd/yyyy') sell_date, 140 dealer_price, 40 discount from dual
union all
select to_date('1/8/2013' , 'mm/dd/yyyy') sell_date, 150 dealer_price, 10 discount from dual
union all
select to_date('1/9/2013' , 'mm/dd/yyyy') sell_date, 200 dealer_price, 20 discount from dual
union all
select to_date('1/10/2013', 'mm/dd/yyyy') sell_date, 100 dealer_price, 10 discount from dual
union all
select to_date('1/11/2013', 'mm/dd/yyyy') sell_date, 120 dealer_price, 30 discount from dual
union all
select to_date('1/12/2013', 'mm/dd/yyyy') sell_date, 140 dealer_price, 20 discount from dual
Net_price and Net_price_before_discount are two calculated columns
Net price = Dealer_price – Discount ( from 2rd day after the current day  , so if we are calculating for 1/4/2013 then the discount should come from 1/6/2013)
Net_ Price_ bd = Dealer_price (  From the 2rd day before the current day, so if we are calculating for 1/4/2013 then the Dealer_price should come from 1/2/2013) – Discount
Please refer below table after the highlighted date
Sell_date(mm/dd/yyyy)
Dealer_Price
Discount
Net Price
Net_Price_bd
Ch_flag
1/1/2013
100
10
90
140
1/2/2013
120
20
100
80
1/3/2013
200
10
190
90
1/4/2013
100
20
70
100
1/5/2013
120
10
80
190
1
1/6/2013
210
30
200
70
1
1/7/2013
140
40
120
80
1/8/2013
150
10
140
200
2
1/9/2013
200
20
170
120
1/10/2013
100
10
80
140
2
1/11/2013
120
30
120
170
1
1/12/2013
140
20
140
80
The task is that if  for a row ch_flag  is set  to 1 (ch_ flag is available in the same  table)  which means Discount has been changed for that row and as  Discount is being used to calculate the Net_price  (for sell_date-2)  and Net_Price_bd ( for sell_date) , corresoding records should get changed.
If for a row ch_flag is set to 2 which means Dealer_price has been changed for that row  and as Dealer_price is being used to calculate the net_price ( for sell_date) and Net_Price_bd ( sell_date +2 ), corresponding records should also get changed
e.g.   Say Discount has been modified for sell_date 1/5/2013 the flag is set to 1 , now Net_price_bd for sell_date and Net_price for sell_date -2 should get recalculated.
Please suggest me.
There will be multiple rows with ch_flag 1 and 2 , so i need to update all the corresonding rows in a single shot.
Can it be achived through Merge ?
Ab

Below may be a possible solution to your problem:
alter session set nls_date_format = 'mm/dd/yyyy';
drop table test_table;
create table test_table as
select to_date('1/1/2013' , 'mm/dd/yyyy') sell_date, 100 dealer_price, 10 discount from dual union all
select to_date('1/2/2013' , 'mm/dd/yyyy') sell_date, 120 dealer_price, 20 discount from dual union all
select to_date('1/3/2013' , 'mm/dd/yyyy') sell_date, 200 dealer_price, 10 discount from dual union all
select to_date('1/4/2013' , 'mm/dd/yyyy') sell_date, 100 dealer_price, 20 discount from dual union all
select to_date('1/5/2013' , 'mm/dd/yyyy') sell_date, 120 dealer_price, 10 discount from dual union all
select to_date('1/6/2013' , 'mm/dd/yyyy') sell_date, 210 dealer_price, 30 discount from dual union all
select to_date('1/7/2013' , 'mm/dd/yyyy') sell_date, 140 dealer_price, 40 discount from dual union all
select to_date('1/8/2013' , 'mm/dd/yyyy') sell_date, 150 dealer_price, 10 discount from dual union all
select to_date('1/9/2013' , 'mm/dd/yyyy') sell_date, 200 dealer_price, 20 discount from dual union all
select to_date('1/10/2013', 'mm/dd/yyyy') sell_date, 100 dealer_price, 10 discount from dual union all
select to_date('1/11/2013', 'mm/dd/yyyy') sell_date, 120 dealer_price, 30 discount from dual union all
select to_date('1/12/2013', 'mm/dd/yyyy') sell_date, 140 dealer_price, 20 discount from dual;
table test_table created.
alter table test_table add net_price number;
alter table test_table add net_price_bd number;
alter table test_table add ch_flag number;
table test_table altered.
--Calculate and update the Net Price and Net Price BD
merge into test_table t
using (
select sell_date,
       dealer_price,
       discount,
       dealer_price - lead(discount, 2, 0) over(order by sell_date) net_price,
       lag(dealer_price, 2, 0) over (order by sell_date) - discount net_price_bd,
       ch_flag
  from test_table
) s
on (t.sell_date = s.sell_date)
when matched then
  update set net_price = s.net_price, net_price_bd = s.net_price_bd;
12 rows merged.
Now, Lets see how the data looks:
select *
  from test_table;
SELL_DATE                 DEALER_PRICE           DISCOUNT               NET_PRICE              NET_PRICE_BD           CH_FLAG               
01/01/2013                100                    10                     90                     -10                                          
01/02/2013                120                    20                     100                    -20                                          
01/03/2013                200                    10                     190                    90                                           
01/04/2013                100                    20                     70                     100                                          
01/05/2013                120                    10                     80                     190                                          
01/06/2013                210                    30                     200                    70                                           
01/07/2013                140                    40                     120                    80                                           
01/08/2013                150                    10                     140                    200                                          
01/09/2013                200                    20                     170                    120                                          
01/10/2013                100                    10                     80                     140                                          
01/11/2013                120                    30                     120                    170                                          
01/12/2013                140                    20                     140                    80                                           
12 rows selected
Now, update few discounts and dealer price and set corresponding CH_FLAG.
update test_table set discount = 15, ch_flag = 1 where sell_date =  to_date('01/05/2013');
update test_table set discount = 25, ch_flag = 1 where sell_date =  to_date('01/06/2013');
update test_table set discount = 35, ch_flag = 1 where sell_date =  to_date('01/11/2013');
update test_table set dealer_price = 175, ch_flag = 2 where sell_date =  to_date('01/08/2013');
update test_table set dealer_price = 110, ch_flag = 2 where sell_date =  to_date('01/10/2013');
commit;
Update the TEST_TABLE for the rows dependent on previous/later dates, where the discount and/or dealer price is modified:
merge into test_table t
using
  select sell_date,
         discount,
         dealer_price,
         decode(a.prev_ch_flag, 1, dealer_price - next_discount, net_price) upd_net_price,
         decode(a.prev_ch_flag, 1, 'Modified', 'Same') is_net_price_modified,
         decode(a.next_ch_flag, 2, next_dealer - discount, net_price_bd) upd_net_price_bd,
         decode(a.next_ch_flag, 2, 'Modified', 'Same') is_net_price_bd_modified,
         ch_flag,
         next_ch_flag,
         prev_ch_flag
    from (
          select sell_date,
                 discount,
                 lead(discount, 2, 0) over(order by sell_date) next_discount,
                 dealer_price,
                 lag(dealer_price, 2, 0) over (order by sell_date) next_dealer,
                 ch_flag,
                 lead(ch_flag, 2, 0) over (order by sell_date) next_ch_flag,
                 lag(ch_flag, 2, 0) over (order by sell_date) prev_ch_flag,
                 net_price,
                 net_price_bd
            from test_table
         ) a
) s
on (t.sell_date = s.sell_date and (s.is_net_price_modified = 'Modified' or s.is_net_price_bd_modified = 'Modified'))
when matched then
  update set net_price = s.upd_net_price, net_price_bd = s.upd_net_price_bd;
3 rows merged.
Now, lets see the final data:
select *
  from test_table;
SELL_DATE                 DEALER_PRICE           DISCOUNT               NET_PRICE              NET_PRICE_BD           CH_FLAG               
01/01/2013                100                    10                     90                     -10                                          
01/02/2013                120                    20                     100                    -20                                          
01/03/2013                200                    10                     190                    90                                           
01/04/2013                100                    20                     70                     100                                          
01/05/2013                120                    15                     80                     190                    1                     
01/06/2013                210                    25                     200                    75                     1                     
01/07/2013                140                    40                     120                    80                                           
01/08/2013                175                    10                     165                    200                    2                     
01/09/2013                200                    20                     170                    120                                          
01/10/2013                110                    10                     80                     140                    2                     
01/11/2013                120                    35                     120                    170                    1                     
01/12/2013                140                    20                     140                    80                                           
12 rows selected
This operation is possible using a regular Update, but not sure why I did not use it; perhaps I was thinking weird while arriving at solution

Similar Messages

  • Reports Query Doubt??

    hi all,
    Thanks to ALL the replies to my query.
    I have a doubt in Oracle reports.
    This is the query in the format trigger.
    ctr,cnt - are summary columns in the group above which counts the detail group
    I have to retrieve the records for status codes equal to active and cancelled.
    and suppress the records with no records for either of these status codes
    if :ctr <> 0 and :cnt <> 0 and :status_code in ('act,'can') then
    return(true);
    else
    return(false);
    end if;
    Now the records with status code 'can'
    are not been retrieved.
    Could you please suggest as to how I could
    rectify where Iam going wrong.
    TIA
    sg
    null

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by ():
    Why don't you use a decode in your query?<HR></BLOCKQUOTE>
    if :ctr <> 0 and :cnt <> 0 and
    (:status_code = 'act' or
    :status_code = 'can') then
    return(true);
    else
    return(false);
    end if;
    null

  • Simple abap query doubt

    Hello all,
       i have one simple doubt plz help.
    data:begin of itab1 occurs 0,
         psnfh like plfh-psnfh,
         end of itab1.
    select  psnfh  into table itab1
    from plfh
                     where plnty = 'N'
                     AND plnNR = group_number
                     AND plnfl  = W_PRT_ASSIGN-SEQUENCE_NO
                     and loekz ne 'X'
                    and plnkn = t_plnkn.
    this query is working fine.
            now i have 3 psnfh entires(0010 0020 0030) ..my requirement is that i have choose maximum of these that is 0030 and wanna add 0010 to it everytime.....and may be it will be better if i can save it in a variable.......
         plz help in this syntax......i know we can use MAX function but it will be better if u can give that exact 2-3 lines of code.

    Hi Abhijeet,
    Do you always want to add "0010" to the maximum value from that internal table?
    If yes, then you can follow the steps mentioned below.
    1. Declare temporary internal table and transfer al values from your main internal table to the temporary.
    ITAB_TEMP[] = ITAB[].
    2. Now Sort the temp table as follows.
    SORT ITAB_TEMP BY fieldname DESCENDING.
    3. Now if you READ this temp table with INDEX 1, you wil get the maximum value to which you can add the value.
    READ TABLE ITAB_TEMP INTO W_ITAB INDEX 1.
    IF SY-SUBRC EQ 0.
      V_MAX = W_ITAB-field + 0010.
    ENDIF.
    Best Regards,
    Ram.

  • Dynamic Query Doubt

    Hi,
    I need to write a Dynamic Query to get the data from the table by using the Input date parameters.
    LIke,
    SELECT* from table where date_start between to_date('12-14-2004','mm-dd-yyyy') AND
    to_date('12-15-2005','mm-dd-yyyy');
    How can i write the above query in dynamic sql as i will get the two dates as input in my procedure
    Help me in this

    Or more preferably use bind variables with the
    EXECUTE IMMEDIATE as, if the query will be called
    many times, the bind variables will prevent hard
    parsing of the statement each time (i.e. it will be
    quicker to execute).blushadow,
    Yes, the execute immediate using bind variables is better/faster than not using bind variables, but your first example outperforms your second one. This is due to the fact that execute immediate really closes all cursors, and in your first example the cursors are kept open (yes, even though you issue a CLOSE cur_test) in the PL/SQL cursor cache.
    SQL> create table i_links
      2  as
      3  select sysdate - l linkdate from (select level l from dual connect by level <= 10000)
      4  /
    Tabel is aangemaakt.
    SQL> exec dbms_stats.gather_table_stats(user,'I_LINKS')
    PL/SQL-procedure is geslaagd.
    SQL> create or replace procedure test1 (start_date in date, end_date in date) as
      2    CURSOR cur_test IS
      3      SELECT count(*)
      4      FROM   i_links
      5      WHERE  linkdate BETWEEN start_date AND end_date;
      6    v_count NUMBER;
      7  begin
      8    OPEN cur_test;
      9    FETCH cur_test INTO v_count;
    10    CLOSE cur_test;
    11    --DBMS_OUTPUT.PUT_LINE('Count: '||v_count);
    12  end;
    13  /
    Procedure is aangemaakt.
    SQL> create or replace procedure test2 (start_date in date, end_date in date) as
      2    v_count NUMBER;
      3  begin
      4    EXECUTE IMMEDIATE 'SELECT count(*) FROM i_links WHERE linkdate BETWEEN :x1 AND :x2' INTO v_count USING start_date, end_date;
      5    --DBMS_OUTPUT.PUT_LINE('Count: '||v_count);
      6  end;
      7  /
    Procedure is aangemaakt.
    SQL> begin
      2    -- warm up
      3    test1(sysdate-365,sysdate);
      4    test2(sysdate-365,sysdate);
      5    -- begin test
      6    runstats_pkg.rs_start;
      7    for i in 1..1000
      8    loop
      9      test1(sysdate-365,sysdate);
    10    end loop;
    11    runstats_pkg.rs_middle;
    12    for i in 1..1000
    13    loop
    14      test2(sysdate-365,sysdate);
    15    end loop;
    16    runstats_pkg.rs_stop(100);
    17  end;
    18  /
    Run1 draaide in 341 hsecs
    Run2 draaide in 348 hsecs
    Run1 draaide in 97,99% van de tijd
    Naam                                                    Run1      Run2  Verschil
    STAT.session cursor cache hits                             0       998       998
    STAT.opened cursors cumulative                             0     1,000     1,000
    STAT.parse count (total)                                   0     1,000     1,000
    LATCH.shared pool                                      1,047     3,043     1,996
    STAT.recursive calls                                   3,001     1,001    -2,000
    LATCH.library cache pin allocation                         8     2,011     2,003
    LATCH.library cache pin 2,048 6,044 3,996
    LATCH.library cache 2,056 6,060 4,004
    Run1 latches totaal versus run2 -- verschil en percentage
          Run1      Run2  Verschil     Pct
        48,522    60,548    12,026  80.14%
    PL/SQL-procedure is geslaagd.Regards,
    Rob.

  • ABAP Query Doubt

    Hi All,
           I am using the ABAP query using the infoset Logical database PNPCE.
    When i select the fields for the output i am getting it. But i need to make some of the fields as mandatory in the selection screen.
    How can i make it.
    Regards,
    Yogesh

    Hello,
    Go to the info set of the query.
    SQ02 -> Enter the infoset name  -> click on 'Change'
    Go to the 'Selections' tab.
    There you will find all the selction screen parameters. Double click on the selection parameter which you want to make it a mandatory field.
    It will pop-up a dialog screen. On  this dialog screen on the input field 'Extras'
    enter the key word OBLIGATORY. Than don't forget to regenarate the infosets again.
    This will solve your problem.
    Regards,
    A.Singh

  • SQL Query doubt

    Hi,
    I have a Customer info table Table1
    it has the following fields apart from many other fields like cust account info.
    Account_number
    Tax_id
    Tax_ID_format (this field has values S, T and the column is NUllable.
    I need to find all the tax ids that have both format codes S and T. This is not common as every tax_id is either S or T. But there can be an instance when both of them can be same that is the SSN and TIN number being same as both do not originate from the same system.
    The query i used is:
    SELECT A.ACCT_NUM, A.TAX_ID, A.TX_FMT_CD
    FROM
    ACCOUNT A
    WHERE A.TAX_ID IN
    SELECT B.TAX_ID FROM
    ACCOUNT B
    WHERE B.TAX_FMT_CD = 'S'
    AND A.TX_FMT_CD = 'T'
    ORDER BY A.TAX_ID
    The results are all messed up. Any help can be appreciated. Thank you.

    Hi,
    Jut another way.
    Assuming you dont have Y,X and Z as your tax_is_format.
    WITH DATA AS(
    SELECT 1 acct_no,'A' tax_id,'S'  tax_id_format FROM dual UNION ALL
    SELECT 2 acct_no,'B' tax_id,'S'  tax_id_format FROM dual UNION ALL
    SELECT 3 acct_no,'C' tax_id,'S'  tax_id_format FROM dual UNION ALL
    SELECT 4 acct_no,'D' tax_id,'S'  tax_id_format FROM dual UNION ALL
    SELECT 5 acct_no,'E' tax_id,'S'  tax_id_format FROM dual UNION ALL
    SELECT 1 acct_no,'A' tax_id,'T'  tax_id_format FROM dual UNION ALL
    SELECT 2 acct_no,'B' tax_id,'T'  tax_id_format FROM dual UNION ALL
    SELECT 1 acct_no,'A' tax_id,'S'  tax_id_format FROM dual UNION ALL
    SELECT 1 acct_no,'C' tax_id,'S'  tax_id_format FROM dual UNION ALL
    SELECT 1 acct_no,'C' tax_id,'T'  tax_id_format FROM dual UNION ALL
    SELECT 1 acct_no,'C' tax_id,NULL  tax_id_format FROM dual UNION ALL
    SELECT 1 acct_no,'C' tax_id,NULL  tax_id_format FROM dual
    SELECT DISTINCT tax_id FROM(
    SELECT acct_no,tax_id,tax_id_format,
    COUNT(DISTINCT nvl(decode(tax_id_format,'S','Y','T','X','Z'),'Z')) over (PARTITION BY tax_id) cnt
    FROM DATA
    WHERE tax_id_format IS NOT NULL
    WHERE cnt=2
    Cheers!!!
    Bhushan

  • Hi sap query doubt

    where shud we add two additional fields in SAP query ? actually i am not able to locate the query but i have the program whch is generated along it . so in whch section of the query i shud write the logic to get two additional fields ?

    Hi,
    Already there are some Infosets (tables) defined in that query.
    Go to that infosets and add extra fields which are there in those tables
    or add extra infoset(table) and link it to the existing table with the key, then add that table field.
    No need to write the code.
    Only thing is to select that field on to the Selection screen or on to the output is required.
    See the help:
    http://help.sap.com/saphelp_46c/helpdata/en/35/26b413afab52b9e10000009b38f974/content.htm
    http://www.thespot4sap.com/Articles/SAP_ABAP_Queries_Introduction.asp
    Step-by-step guide for creating ABAP query
    http://www.sappoint.com/abap/ab4query.pdf
    ABAP query is mostly used by functional consultants.
    SAP Query
    Purpose
    The SAP Query application is used to create lists not already contained in the SAP standard system. It has been designed for users with little or no knowledge of the SAP programming language ABAP. SAP Query offers users a broad range of ways to define reporting programs and create different types of reports such as basic lists, statistics, and ranked lists.
    Features
    SAP Query's range of functions corresponds to the classical reporting functions available in the system. Requirements in this area such as list, statistic, or ranked list creation can be met using queries.
    All the data required by users for their lists can be selected from any SAP table created by the customer.
    To define a report, you first have to enter individual texts, such as titles, and select the fields and options which determine the report layout. Then you can edit list display in WYSIWYG mode whenever you want using drag and drop and the other toolbox functions available.
    ABAP Query, as far as I Believe, is the use of select statements in the ABAP Programming. This needs a knowledge of Open SQL commands like Select,UPdtae, Modify etc. This has to be done only by someone who has a little bit of ABAP experience.
    To sum up, SAP queries are readymade programs given by SAP, which the user can use making slight modification like the slection texts, the tables from which the data is to be retrieved and the format in which the data is to be displayed.ABAP queries become imperative when there is no such SAP query existing and also when there is a lot of customizing involved to use a SAP Query directly
    use either SQ02 ans SQ01
    or SQVI tr code
    for more information please go thru this url:
    http://www.thespot4sap.com/Articles/SAP_ABAP_Queries_Create_The_Query.asp
    http://goldenink.com/abap/sap_query.html
    Please check this PDF document (starting page 352) perhaps it will help u.
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVQUE/BCSRVQUE.pdf
    check the below link will be helpful for u
    Tutorial on SQVI
    once you create query system generates a report starting with AQZZ/SAPQUERY/ABAGENCY2======= assing this report to tr code for the same
    reward if useful
    regards,
    Anji

  • Select query doubt

    hello all,
    i am writting this code .....first select is working fine for me as i am getting 5 entires in  table itab which i am expecting...
    but for second when i loop itab itab then at that time i should get one record  in table itab2 out of second select query........
    but as i can see while debugging  i am getting that entry at third time when i am in loop.....but it again i think it overwrites with next enter and making itab2 entry as 0 at the end.....
    what might be problem.
    even i write append itab2.
                        clear itab2.
    same error i am getting...(here CDPOS is cluster table..is this because of this??)..pease help
    selection-screen:begin of block test with frame title new.
    select-options: s_ddate for vbak-vdatu.
    selection-screen:end of block test.
    select avbeln avdatu bnetpr bnetwr b~matnr into corresponding fields of table itab
        from vbak as a inner join vbap as b on avbeln = bvbeln where
           b~matnr = 'AUP-501'
        and a~vdatu in s_ddate.
    LOOP AT ITAB.
    select *  from CDPOS into table itab2 where
      OBJECTID = ITAB-VBELN AND
      TABNAME = 'VBAP' AND
      FNAME = 'NETPR'.
    ENDLOOP.

    Hi,
    You are completely into wrong performance..
    as per your query
    selection-screen:begin of block test with frame title new.
    select-options: s_ddate for vbak-vdatu.
    selection-screen:end of block test.
    select avbeln avdatu bnetpr bnetwr b~matnr into corresponding fields of table itab
    from vbak as a inner join vbap as b on avbeln = bvbeln where
    b~matnr = 'AUP-501'
    and a~vdatu in s_ddate.
    LOOP AT ITAB.
    select * from CDPOS into table itab2 where
    OBJECTID = ITAB-VBELN AND
    TABNAME = 'VBAP' AND
    FNAME = 'NETPR'.
    ENDLOOP.
    The second query is inside loop and its moving data into itab2 for every record in internnale table ITAB and
    finally itab2 contains the last records of ITAB data if CDPOs has the data for itab-vbeln(last records).
    To over come you need to write the select as beloew
    select * from CDPOS APPENDING table itab2 where
    OBJECTID = ITAB-VBELN AND
    TABNAME = 'VBAP' AND
    FNAME = 'NETPR'.
    But I suggest you to write for all entries
    select <the filed you need> from CDPOS
    into table itab2
    for all entries in itab
    where OBJECTID = ITAB-VBELN AND
    TABNAME = 'VBAP' AND FNAME = 'NETPR'.
    Then
    loop at ITAB.
    Read table itab2 with key vbeln = itab-vbeln binary search.
    If sy-subrc = 0.
    <Write your code, functions etc>.
    endif.
    endloop.
    regards,
    Nazeer

  • SAP Query Doubt

    Hi, Guys!
        I'm trying to create a SAP Query, which should display the old and the new position of employee.
        The problem is that the SAP Query generates 2 lines for each position, the employee had.
       We need a report that display in two or tree a column for each position the employee had. And we have one line for each employee.
        Can we do this in SAP Query? Or will we need a development for this report?
    Regards,

    If it is just an addition of previous/old position, I would recommend creating a new field and field group within the infoset of SAP query framework. You may also have to write a small piece of code within the infoset to populate the field value.
    If your business scenario is getting complex it is better to have a simple ABAP report rather than enhancing the SAP query.
    Thanks
    Ravikumar

  • Update query doubt

    I have table with two columns as given below ....
    Name sex
    ab m
    ac m
    ad m
    ae m
    ba f
    bb f
    bc f
    bd f
    I have to change all 'm' to 'f' and all 'f' to 'm'..... I have tried this using rowid and collection and I was able to do this. Is there other way to do this with simple SQL query????? Please somebody help....
    thanks in advance
    Prabu.....

    update your_table
    set    s_e_x = (case s_e_x
                         when 'm' then 'f'
                         when 'f' then 'm'
                    end
    where s_e_x in ('m','f');

  • A query doubt.

    Hello All,
    I have a query to be defined.  I have an existing variable for year/month. Query that should be defined is..
    User should enter two period intervals ( eg: jan till march & may till july) For these two periods i should produce a comparison of price for these period(key figure comparison). Can anybody gimme an idea to create the query.
    Thanks
    Krishna

    Hi Krishna,
    Without these variables you can only restrict your KFs in the query designer by fixed values (months) and change these restriction every time the user needs another report.
    So, either get authorization or try to find variables already created that suit your needs or ask authorized persons to cretae variables.
    During query desing you'll do the following:
    - create a structure in rows.
    - create a new selection and put there your KF and 0calmonth. Restrict the latter by a user entry 1st month range.
    - Do the same for the 2nd month range.
    - Create a new variable. There insert any logic for comparing the previous selections.
    Best regards,
    Eugene

  • Query  doubt - Please Help

    Sir,
    I am having a table like following
    Deptno job
    10 aaa
    11 bbb
    12 ccc
    10 ddd
    11 eee
    12 ffff
    10 ggg
    in the above table I want the out put like following in a single query ,is it possible.
    10 aaa,ddd,ggg (concatenation of all jobs under that particular deptno)
    11 bbb,eee
    12 ccc,ffff
    Regards,
    Mathew

    Sir,
    I am not able to cutomize my requirement using this,
    SQL> select col1, col2,
    2 substr(max(substr(sys_connect_by_path (col3||' '||
    3 col4, ', '),2)),1,60)
    4 as col3
    5 from tab1
    6 start with col4 = 1
    7 connect by col4 = prior col4 + 1
    8 and prior col1 = col1
    9 and prior col2 = col2
    10 group by col1, col2;
    plz help me.
    regards
    Mathew

  • Essbase Studio SQL Query Doubt

    Hi All,
    Can some on explain me what does the below statements mean realted to Data Load SQL Override Editing
    "If a member is prefixed with previous members of its dimension (for example, parent or all ancestors), more columns are returned.
    ● If some columns in the data load SQL statements are NULL, you can add SQL statements to load the data at the next level in the outline. This is known as NULL Promotions."
    Thanks,
    SatyaB

    can you explian what does this where name < 'S' means??
    Thanks in advance
    Sajithit will display the names in allphapatecal order A TO R
    it wont display NAMES WITH S T UVWXYZ
    s

  • Query doubt again

    Hello Friends,
    SET SERVEROUTPUT ON;
    DECLARE
    vMemName VARCHAR2(100) DEFAULT '';
    vName VARCHAR2(100) DEFAULT '';
    BEGIN
    FOR I IN (SELECT EMAIL FROM MYTABLE WHERE ID <10)LOOP
    IF vMemName IS NULL THEN
    vMemName := I.MEM_EMAIL;
    ELSE
    vName := CONCAT(CONCAT(vName,','),vMemName);
    END IF;
    END LOOP;
    DBMS_OUTPUT.PUT_LINE('The Name :'||vName);
    END;
    ORA-06502: PL/SQL: numeric or value error
    ORA-06512: at line 9
    y?..What's the wrong here ?

    Hmm, I think it would be better to limit it:
    SELECT SUM(length(EMAIL )) + count(EMAIL ) - 100 FROM MYTABLE where id < 10
    (this is trying to find the amount you'll need to extend your variable by)

  • Paging using JSF

    Hi All,
    OK, I would like to know the better idea for paging in JSF
    Now current Idea what Creator team has implemented seems to be not the right way. It is just my perception. I don't know if I am right or wrong. Please clarify me on this.
    Why I am not interested on Current Implemetation of Paging by Creator team is because, considering the below codes generated by creator,
    <h:dataTable binding="#{Page5.myDataTable}" headerClass="list-header" id="myDataTable" rowClasses="list-row-even,list-row-odd" rows="15"
                            style="left: 216px; top: 144px; position: absolute" value="#{Page5.myDataTableModel}" var="currentRow">
    </h:dataTable>                       
    Here basically Some tag lib is handling the paging of entire dataTable. So when ever the page is rendered, rowset will be traversed totally and on conditional basis it grabs and holds the required data in the dataTable
        jiya_userRowSet.setCommand("SELECT ALL JIYA_USER.USER_ID, JIYA_USER.LOGIN_ID, JIYA_USER.USER_FNAME, JIYA_USER.USER_LNAME  FROM JIYA_USER");
                myDataTableModel.setDataCacheKey("com.sun.datacache.Page5.jiya_userRowSet");
                myDataTableModel.setRowSet(jiya_userRowSet);
                myDataTableModel.setSchemaName("");
                myDataTableModel.setTableName("JIYA_USER");
    Now considering above code , although RowSetDataModel supports caching, it is not compulsory that a developer should depend on RowSetDataModel class implementation and bind this to dataTable. There is a chance where developer can use array of beans and bind this to dataTable. So caching may not be possible in this scenario. So obviously whenever page is rendered , it should access the managed bean class and execute the rowset .
    So assuming the rowset holds the 10000 records for an example, the idea what Creator team has implemented is very poor. beacuse for page size of 10, application has to fetch the records 1000 times means (1000 X 10000) . 100 lacs of records need to be fetched from the database. So, we are just increasing the burden on database server and application server.
       public String myDataTable_firstPageAction() {
            myDataTable.setFirst(0);
            return null;
        public String myDataTable_previousPageAction() {
            int first = myDataTable.getFirst() - myDataTable.getRows();
            if (first < 0) {
                first = 0;
            myDataTable.setFirst(first);
            return null;
        public String myDataTable_nextPageAction() {
            int first = myDataTable.getFirst() + myDataTable.getRows();
            myDataTable.setRowIndex(first);
            if (myDataTable.isRowAvailable()) {
                myDataTable.setFirst(first);
            return null;
        public String myDataTable_lastPageAction() {
            int first = myDataTable.getFirst();
            while (true) {
                myDataTable.setRowIndex(first + 1);
                if (myDataTable.isRowAvailable()) {
                    first++;
                } else {
                    break;
            myDataTable.setFirst(first - (first % myDataTable.getRows()));
            return null;
        }That is the reason I am looking for an alternate idea for paging in JSF
    Hope you understand my query,doubts , concerns regarding Creator team's implementation of paging the data
    Best Regards
    Sudhakar

    Hi Sudhakar,
    You can definitely restrict the number of rows fetched by a rowset. Here is how you do it:
    1. Drag and drop a table onto the design view
    2. in the properties sheet, under General there is a property named maxRows.
    3. Enter the max rows you want to retrieve from the database table, for example 5
    This will fetch only 5 rows and display them in the datatable.
    I hope this was what you were looking for
    Cheers
    Giri :-)
    Creator Team

Maybe you are looking for