Group by based upon condition

Database : SQL Server 2000 Enterprise Edition
OS : Windows Server 2003
Huh?  Every one will ask me why I am posting SQL Server question in Oracle forum ?  I shall reply something like this :
Actually my friend is SQL Server DBA and he is getting problem to solve the below query.  He asked me to solve in Oracle 9i (Because since he is using SQL Server 2000, so I guess it is almost similar level) and/or through pure SQL; but I am really very poor in SQL (need to read docs more times); I failed to help him.  He just asked me how to solve in Oracle and if it is solve in Oracle then he will try to solve in by looking similar function in SQL Server's functions etc.  Even though, I have posted the question in two SQL Server forums, but probably there is less activity, so I am posting here :
create table student
rollno int,
name varchar(30),
class varchar(20)
insert into student values (1,'Robert','IT');
insert into student values (2,'John','Arts');
insert into student values (2,'Hussain','IT');
insert into student values (1,'David','Science');
insert into student values (3,'Polo','IT');
insert into student values (2,'Jonathan','Science');
insert into student values (4,'Joseph','History');
insert into student values (1,'Richard','History');
insert into student values (1,'Michel','Commerce');
insert into student values (1,'Albert','Geography');
SQL> select * from student;
    ROLLNO NAME                           CLASS
         1 Robert                         IT
         2 John                           Arts
         2 Hussain                        IT
         1 David                          Science
         3 Polo                           IT
         2 Jonathan                       Science
         4 Joseph                         History
         1 Richard                        History
         1 Michel                         Commerce
         1 Albert                         Geography
10 rows selected.
SQL>
Required Output :
rollno  name        class
1        Robert      IT
2        Hussain     IT
3        Polo        IT
4        Joseph      History
Logic behind required ouput : Rollno should be unique from all the classes giving priority to :
1.IT
2.Science
3.Arts
4.Commerce
5.Geography
6.Anyone
means, if suppose we are going to fetch a unique roll number (x), and if it is exists in all the classes then first it should be from IT, and if it is not in IT class then it should search in Science Class, if it is not in IT and Science class, then it should search in Arts class, if it is not in IT, Science,Arts then it should search in Commerce Class; like wise. All existing roll numbers must be unique from all classes giving priority to IT, Science, Arts, Commerce, Geography and if that unique roll number is not from above 5 classes, then it may be of any one class.
Kindly let me know, if I am unclear in my question and/or needs to provide more details. Since my friend is using SQL Server 2000, so I would like to request to please help me/him by using simple SQL please.
Thanks and Regards
Girish Sharma

Probably need more test cases:
        SELECT ROLLNO, NAME, CLASS
  FROM (SELECT a.*,
               RANK ()
               OVER (
                  PARTITION BY rollno
                  ORDER BY
                     (CASE
                         WHEN class = 'IT' THEN 1
                         WHEN class = 'Science' THEN 2
                         WHEN class = 'Arts' THEN 3
                         WHEN class = 'Commerce' THEN 4
                         WHEN class = 'Geography' THEN 5
                         ELSE 6
                      END))
                  rnk
          FROM student a)
WHERE rnk = 1;
ROLLNO NAME CLASS
1 Robert IT
2 Hussain IT
3 Polo IT
4 Joseph History
Cheers,
Manik.

Similar Messages

  • Display an image based upon condition A

    I am displaying layers based upon windows username. If User B, then Layer B. If Username A, then Layer A. etc. Do you see that is compatible with Acrobat Reader 9? It would appear as if the OCG methods will not work as Reader doesn't support the setIntent OCG object Maybe with another function like backgrounds or watermarks?
    The only thing the layer contains is a picture. Can we get the pictures to display using another method other then OCG?
    Please advise.

    You can place a picture as a button icon. You can also show/hide buttons with JavaScript.
    George

  • To get the sum of column of SAPScript based upon condition

    Hi,
    I was first asked to get two new columns in ZF140_ACC_STAT_01 script with ZRFKORD10 print program. I did so by the writing the below code. Now, based on Document-Type (RV,DR,DZ,SA), all the amount with same Document Type are needed to be summed and assigned to separate variables.
    How to get that done????? Please help me out.
    PRINT-PROGRAM:-
    FORM sep_amt_open TABLES in_par STRUCTURE itcsy
                         out_par STRUCTURE itcsy.
    DATA: wf_temp_amt_open TYPE string,"rf140-wrshb,
           amount_open TYPE string,
           amt_shkzg_open TYPE bsid-shkzg,
           doc_desc TYPE t003t-ltext.
    READ TABLE in_par WITH KEY name = 'RF140-BELEGNUM'.   " document no
       IF SY-SUBRC = 0.
       SELECT SINGLE SHKZG FROM BSID INTO (amt_shkzg_open)
         WHERE BELNR = IN_PAR-VALUE.
    ENDIF.
    READ TABLE in_par WITH KEY name = 'T003T-BLART'.     " document description
       IF sy-subrc = 0.
        SELECT SINGLE LTEXT FROM T003T INTO (doc_desc)
          WHERE SPRAS = 'E' AND BLART = IN_PAR-VALUE.
       IF sy-subrc = 0.
         READ TABLE out_par WITH KEY name = 'DOC_DESC'.
          IF SY-SUBRC = 0.
            OUT_PAR-VALUE = DOC_DESC.
            MODIFY OUT_PAR INDEX SY-TABIX.
          ENDIF.
       ENDIF.
      ENDIF.
      READ TABLE in_par WITH KEY name = 'RF140-WRSHB'.    " Amount
        IF sy-subrc = 0.
         wf_temp_amt_open = in_par-value.
       ENDIF.
      call function 'CONVERSION_EXIT_ALPHA_INPUT'
        exporting
          input         = wf_temp_amt_open
       IMPORTING
         OUTPUT        = amount_open
    IF amt_shkzg_open = 'S'.
        READ TABLE out_par WITH KEY name = 'DEBIT_OPEN'.
         IF SY-SUBRC = 0.
           out_par-value = amount_open.
           MODIFY out_par INDEX sy-tabix.
           CLEAR out_par.
         ENDIF.
    ELSEIF amt_shkzg_open = 'H'.
        READ TABLE out_par WITH KEY name = 'CREDIT_OPEN'.
         IF SY-SUBRC = 0.
           out_par-value = amount_open.
           MODIFY out_par INDEX sy-tabix.
           CLEAR out_par.
         ENDIF.
      ENDIF.
    ENDFORM.
    SAPSCRIPT:-
    /:DEFINE &DEBIT_OPEN& = ' '
    /:DEFINE &CREDIT_CLEAR& = ' '
    /:DEFINE &DOC_DESC& = ' '
    /:PERFORM SEP_AMT_OPEN IN PROGRAM ZF27_DRIVER_PROGRAM
    /:USING &RF140-BELEGNUM&
    /:USING &T003T-BLART&
    /:USING &RF140-WRSHB&
    /:CHANGING &DEBIT_OPEN&
    /:CHANGING &CREDIT_OPEN&
    /:CHANGING &DOC_DESC&
    /:ENDPERFORM
    T1 &RF140-BELEGNUM&,,&BSID-BLDAT&,,&T003T-BLART&,,&BSID-WAERS&,,&DOC_DESC&
    =  ,, &DEBIT_OPEN&,,&CREDIT_OPEN&,,
    T1 ,,&BSID-SGTXT&
    Thanks & Regards,
    Rakesh Nair

    If you are mentioning about table/advanced table region you can enable totalling in those regions. Please check the Table / Advanced Table section as appropriate in Chapter 4 of the dev guide.
    If it is not a table / advancedTable then you will have to programmatically total the column value and display it in the appropriate cell.

  • How to disable and enable Check box based upon condition

    Hi,
    I wants to disable/hide the check box field before the required field is filled.   Kindly help me

    Hi Mohammed,
    Try to use customize InfoPath form, add rules. Go to list tab, click customize Form, then this opens the list form in InfoPath
    format.
    1.Select the check box field control, click add rules, select if is blank, show validation error action.
    2.Then go to conditions, click column name is blank, change it to the required column you want.
    3.Go to rule type, click validation, change it to formatting, select hide this control.
    4.Publish the InfoPath form.
    Best Regards.
    Kelly Chen
    TechNet Community Support

  • Duplicate rows based upon condition

    Oracle 11.2.0.1
    Windows
    create table regsales (billno number,itemno number,paymode varchar2(10));
    insert into regsales values (12345,10,'cash');
    insert into regsales values (12345,11,'cash');
    insert into regsales values (12346,11,'cash');
    insert into regsales values (12347,10,'credit');
    insert into regsales values (12348,14,'cash');
    insert into regsales values (12348,15,'cash');
    insert into regsales values (12345,12,'cash');
    insert into regsales values (12349,10,'cash');
    insert into regsales values (12345,10,'credit');
    insert into regsales values (12350,11,'cash');
    insert into regsales values (12351,12,'cash');
    insert into regsales values (12352,11,'cash');
    insert into regsales values (12350,11,'credit');
    Required Output please :
        BILLNO     ITEMNO PAYMODE
         12345         11 cash
         12345         11 credit
         12350         10 cash
         12350         10 credit
    i.e. in which same billnos same itemno has been sold in cash and credit.
    Thank you.

    Hi,
    So, you need to know how many different paymodes there are in a group of rows.  That sounds like a job for COUNT (DISTINCT ...)
    Here's one way:
    WITH   got_cnt      AS
         SELECT  billno, itemno, paymode
         ,       COUNT (DISTINCT paymode)
                     OVER ( PARTITION BY  billno
                            ,             itemno
                          )  AS cnt
         FROM    regsales
    SELECT    billno, itemno, paymode
    FROM      got_cnt
    WHERE     cnt  = 2
    ORDER BY  billno, itemno, paymode
    Can there be other paymodes besides 'cash' and 'credit'?  If so, the same basic idea will still work, but the details may be a little messier, depending on your requirements.

  • ALV rows coloring based on condition

    Hai ,
    I want Color the rows in the list based on some condition ..
    Hope to get the helpful suggestion s on this asap
    regards,

    Hi shishupalreddy,
    1. Not only the full row color,
      we can also manipulate the color in each cell,
      based upon conditions.
    2.
    IMPORTANT THINGS
    a. Extra field in internal table
    clr TYPE slis_t_specialcol_alv,
    (this field will contain the colour codes)
    b. assign fieldname to alv layout
    alvly-coltab_fieldname = 'CLR'
    c. work area for colour
    DATA : clrwa TYPE slis_specialcol_alv.
    d. Populating the color
    Once again
    Loop at ITAB.
    *********logic
    if itab-field < 0 "---negative
    clrwa-fieldname = 'FIELDNAME'. "<--- FIELDNAME FOR COLOR
    clrwa-color-col = 6. <------- COLOUR 0-9
    APPEND clrwa TO itab-clr.
    MODIFY ITAB.
    endif.
    ENDLOOP.
    5. just copy paste in new program
    6.
    REPORT abc .
    NECESSARY / MUST
    TYPE-POOLS : slis.
    DATA : alvfc TYPE slis_t_fieldcat_alv.
    DATA : alvly TYPE slis_layout_alv.
    ITAB DECLARATION
    DATA : prg TYPE sy-repid.
    DATA : BEGIN OF itab OCCURS 0.
    INCLUDE STRUCTURE t001.
    DATA : clname(3) TYPE c,
    clr TYPE slis_t_specialcol_alv,
    END OF itab.
    DATA : clrwa TYPE slis_specialcol_alv.
    PARAMETERS : a TYPE c.
    DATA : flname TYPE slis_fieldname.
    SELECT
    START-OF-SELECTION.
    SELECT * FROM t001
    INTO CORRESPONDING FIELDS OF TABLE itab..
    LOOP AT itab..
    IF SY-TABIX <= 5.
    itab-clname = 'C50'.
    ELSE.
    itab-clname = 'C30'.
    ENDIF.
    MODIFY itab.
    ENDLOOP.
    LOOP AT ITAB.
    check itab-bukrs = '1000'
    clrwa-fieldname = 'BUTXT'.
    clrwa-color-col = 6.
    APPEND clrwa TO itab-clr.
    MODIFY ITAB.
    clrwa-fieldname = 'LAND1'.
    clrwa-color-col = 4.
    APPEND clrwa TO itab-clr.
    MODIFY ITAB.
    ENDLOOP.
    prg = sy-repid.
    flname = 'CLNAME'.
    alvly-info_fieldname = 'CLNAME'.
    alvly-coltab_fieldname = 'CLR'.
    LOOP AT ITAB.
    if sy-tabix = 3.
    clrwa-fieldname = 'BUTXT'.
    clrwa-color-col = 6.
    APPEND clrwa TO itab-clr.
    MODIFY ITAB.
    clrwa-fieldname = 'LAND1'.
    clrwa-color-col = 1.
    APPEND clrwa TO itab-clr.
    MODIFY ITAB.
    endif.
    ENDLOOP
    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
    i_program_name = prg
    i_internal_tabname = 'ITAB'
    i_inclname = prg
    CHANGING
    ct_fieldcat = alvfc
    EXCEPTIONS
    inconsistent_interface = 1
    program_error = 2
    OTHERS = 3.
    minimum
    *CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    it_fieldcat = alvfc
    TABLES
    t_outtab = itab
    EXCEPTIONS
    program_error = 1
    OTHERS = 2
    extra
    sy-uname = 'XYZAB'.
    prg = sy-repid.
    Excluding
    DATA : excl TYPE slis_t_extab.
    DATA : exclwa TYPE slis_extab.
    exclwa = '&OUP'.
    APPEND exclwa TO excl.
    exclwa = '&ODN'.
    APPEND exclwa TO excl.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    it_fieldcat = alvfc
    i_callback_program = sy-repid
    is_layout = alvly
    i_callback_user_command = 'ITAB_USER_COMMAND'
    it_excluding =
    excl
    i_save = 'A'
    TABLES
    t_outtab = itab
    EXCEPTIONS
    program_error = 1
    OTHERS = 2.
    *& Form itab_user_command
    text
    -->WHATCOMM text
    -->WHATROW text
    FORM itab_user_command USING whatcomm TYPE sy-ucomm whatrow TYPE
    slis_selfield.
    BREAK-POINT.
    ENDFORM. "itab_user_command
    regards,
    amit m.

  • Ssrs sum based upon a conditional statement

    In an ssrs 2008 r2 report, I have the following code that totals a transaction amount:
    =sum(cdec(Fields!TransactionAmount.Value))
    Now I need to have different total amounts based upon 'payment type'. The payment_types are either 'check', or 'credit' for credit card. Thus can you show me how to change the code I just listed to sum the amount depending upon the payment type?

    You may wish to follow this thread that is exploring a similar question.
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/12e2cdf4-1fd7-4f2a-ba12-ff5c4ec01eeb/sum-values-based-on-condition-in-ssrs?forum=sqlreportingservices
    To do this in an SSRS expression just insert an IIf:
    =Sum(IIf(Fields!payment_type.Value = "check",cdec(Fields!TransactionAmount.Value),0))
    =Sum(IIf(Fields!payment_type.Value = "credit",cdec(Fields!TransactionAmount.Value),0))
    In the other thread you will see that sometimes it makes sense to do this kind of work in the dataset since dataset queries run on the datasource and often those systems are robust servers that can crunch and return data very quickly.
    "You will find a fortune, though it will not be the one you seek." -
    Blind Seer, O Brother Where Art Thou
    Please Mark posts as answers or helpful so that others may find the fortune they seek.

  • Is it possible to apply conditional formatting to a cell (or range) based upon a LOOKUP query to cell values in another sheet.? I want to alter the formatting (i.e., text and/or cell background color), but not cell content.

    Is it possible to apply conditional formatting to a cell (or range) based upon a LOOKUP query to cell values in another sheet.?
    I want to alter the formatting (i.e., text and/or cell background color), but not the content, of the target cell(s).

    Hi Tom,
    Your LOOKUP formula will return a value that it finds in the "other" table. That value can be used in conditional highlighting rules. (Numbers 3 calls it conditional highlighting, not conditional formatting. Just to keep us awake, I guess, but it works the same).
    Please explain what you are trying to do.
    Regards,
    Ian.

  • Could you restrict purchase orders based upon Vendor / Material Group?

    Hey everyone - I've got a general "could this be done" kind of question. 
    We would like to add on to the vendor purchasing view to include "valid" material groups.  This would then have what material groups could be purchased for which company code for that vendor.  Then in the purchase order creation / modification we would like to be able to validate this purchase order against this vendor / company code / material group combination.
    Obviously with enough custom code this could be done.  My question is whether it could be done without out introducing too much custom code - how would you construct such a solution to this problem?
    We are a SAP 4.7 shop.
    Thanks!   Ken Little

    >
    Ken Little wrote:
    > Hey everyone - I've got a general "could this be done" kind of question. 
    >
    > We would like to add on to the vendor purchasing view to include "valid" material groups.  This would then have what material groups could be purchased for which company code for that vendor.  Then in the purchase order creation / modification we would like to be able to validate this purchase order against this vendor / company code / material group combination.
    >
    > Obviously with enough custom code this could be done.  My question is whether it could be done without out introducing too much custom code - how would you construct such a solution to this problem?
    >
    > We are a SAP 4.7 shop.
    >
    > Thanks!   Ken Little
    By include "valid" material groups i think it means you are introducing a new field or some value in already existing field in vendor master.
    1) Now to restrict PO based upon material group a small custom code is needed.
        Use BAdI ME_PROCESS_PO_CUST....here write a code with help of your ABAP person that system will first select the 
        LIFNR (vendor code) entered in the PO...then it will check the same LIFNR in LFM1 table...here it will check the material
        group in the customized field & if found that it is within the list of previous listed material group then it will allow to process
        further or otherwise give a customized error message.
    or
    2) Use the field Group in OMSF...here maintain a common group against the material groups you want to do the purchase cycle.Now ask your BASIS person to use this group in carry out a specific activity, the user must have authorization for the combination of the activity and the authorization group.
    Regards,
    Indranil

  • Formula by Group and based on a condition

    Post Author: Ravi
    CA Forum: Formula
    Hi All,
    I need to create a formula by Group and based on a condition. Below the syntax is wrong but this is the calculation that I am after!
    Sum({@Test_Dollars}, ) where {Customer Number} = 12
    Basically, I need to display/calculate the 2nd column in the sample report/output.
                      All Customers                    Only  Customer 12
    Company    $500                                  $125    
        Zone A  $200                                   $50
       Zone B   $300                                   $75
    Thanks in advance,
    Ravi

    Post Author: Jagan
    CA Forum: Formula
    I think you should be able to get this from a running total with a formula to only include records where the customer number - 12

  • Dataset from two set of tables based on condition

    I have two queries that will return same columns from two different set of tables ( column mapping has been taken care of). The return type is out ref cursor. (P_SUPPLY_REORDER )
    Query 1-SO
    select
    so.SMO_NO,
    so.SPLY_ORD_DT,
    so.fk_CUST_ID as CUST_ID,
    so.CUST_PO_NO,
    so.ATTENTION_NAME,
    sum(sol.SPLY_ORD_QTY) as SPLY_ORD_QTY,
    --sum(sol.sply_shp_qty),
    so.ST_NAME,
    so.ADDR_LN_2,
    so.ADDR_LN_3,--sta.SHIP_TO_ADDRESS_LINE_3,
    so.CITY_NAME,
    so.ST_TERR_CD,
    so.ZIP_CD,
    so.SPCL_SHP_INSTR_TXT,
    so.SHP_CNFRM_DT
    ,XCOM_ORDER_NO
    from
    supply_order so,
    supply_order_line sol,
    XCOM_ORDER_HEADER
    where
    so.FK_CUST_ID =in_cust_id
    and so.pc_ord_no = sol.fk_pc_ord_no and
    XCOM_ORDER_HEADER.FK_PC_ORD_NO = so.PC_ORD_NO
    group by so.SMO_NO, so.SPLY_ORD_DT, so.fk_CUST_ID,
    so.CUST_PO_NO, so.ATTENTION_NAME,
    so.ST_NAME, so.ADDR_LN_2, so.ADDR_LN_3, so.CITY_NAME, so.ST_TERR_CD,
    so.ZIP_CD, so.SPCL_SHP_INSTR_TXT, so.SHP_CNFRM_DT, XCOM_ORDER_NO;
    Query-2 Xcom
    select
    null as sMO_NO,
    xso.created_date as SPLY_ORD_DT,
    xso.fk_cust_id as cust_id,
    cust.cust_po_no as cust_PO_NO
    ,(sta.SHIP_TO_ATTN_FIRST_NAME||''||sta.SHIP_TO_ATTN_LAST_NAME) as attention_name,
    xsol.CARTONS_ORDERED as SPLY_ORD_QTY,
    --sum(sol.sply_shp_qty),
    sta.SHIP_TO_ADDRESS_LINE_1 as ST_NAME,
    sta.SHIP_TO_ADDRESS_LINE_2 as ADDR_LN_2,
    --sta.SHIP_TO_ADDRESS_LINE_3,
    NULL as ADDR_LN_3,
    sta.ship_to_city as CITY_NAME,
    sta.SHIP_TO_STATE as ST_TERR_CD,
    sta.SHIP_TO_POSTAL_CODE as ZIP_CD,
    sta.SHIPPING_INSTRUCTIONS as SPCL_SHP_INSTR_TXT,
    null  as SHP_CNFRM_DT,
    xso.XCOM_ORDER_NO as XCOM_ORDER_NO
    from
    XCOM_ORDER_HEADER xso,
    XCOM_ORDER_LINES xsol,
    customer cust,
    ship_to_address sta
    where
    cust.cust_id = xso.fk_cust_id and
    sta.fk_cust_id = xso.fk_cust_id
    and xso.FK_CUST_ID =in_cust_id
    and xso.FK_PC_ORD_NO is null
    and xso.xcom_order_no = xsol.fk_xcom_order_no;Now the requirement is
    One of four conditions are possible for each Supply Reorder Number:
    •     Both table queries return no records
    -     Populate all the P_SUPPLY_REORDER output fields with nulls
    •     SUPPLY_ORDER returns a record, but XCOM_ORDER_HEADER returns no records
    -     Populate output fields with values from the join of SUPPLY_ORDER and SUPPLY_ORDER_LINE.
    •     SUPPLY_ORDER returns no records, but XCOM_ORDER_HEADER returns one record
    -     Populate output fields with values from the join of XCOM_ORDER_HEADER and XCOM_ORDER_LINES.
    •     SUPPLY_ORDER returns a record, and XCOM_ORDER_HEADER returns a record; find out the latest order by comapring max(SPLY_ORD_DT)
    from SUPPLY_ORDER with max(CREATED_DATE) from XCOM_ORDER_HEADER.
    -     If the latest order is in SUPPLY_ORDER, then populate output fields with values from the join of SUPPLY_ORDER and SUPPLY_ORDER_LINE.
    -     If order dates are equal from both join results, then populate output fields with values from the join of SUPPLY_ORDER and SUPPLY_ORDER_LINE.
    -     If the latest order is in XCOM_ORDER_HEADER, then populate output fields with values from the join of XCOM_ORDER_HEADER and XCOM_ORDER_LINES.
    Question is how can we switch over the queries to pull respective dataset based on these conditions ( checking that which table join is going to return a row and then based upon latest order if both tables return a row) and all this logic as part of single SQL statement that is returned as OUT Ref Cursor.
    Your help will be really appreciated. Thanks much in advance.

    It would be easier if you would supply a dataset we can work with. And I assume the queries are called within a other cursor which returns in_cust_id right?
    The best/fasters way would be to say goodbye to nested cursors.
    You need:
    the in_cust_id_query
    extend SUPPLY_ORDER with a new field
    max(CREATED_DATE) over (partiontion by cust_id) max_created_dateextend XCOM_ORDER_HEADER with a new field
    max(SPLY_ORD_DT)over (partiontion by cust_id) max_sply_ord_dateThen you make a 3 level SELECT
    the innerst () join all 3 sources
    the second level names the rule
    the outermost level applies the rule to each field:
    SELECT
    -- case statement to each field:
    CASE rule
    WHEN 1 THEN null
    WHEN 2 THEN s_smo_no
    WHEN 3 .... END  SMO_NO,
    SELECT
    -- check all rules:
    case
    --• Both table queries return no records
    when s_in_cust_id IS NULL and h_in_cust_id IS NULL then 1
    --• SUPPLY_ORDER returns a record, but XCOM_ORDER_HEADER returns no records
    when s_in_cust_id IS NOT NULL and h_in_cust_id IS NULL then 2
    --• SUPPLY_ORDER returns no records, but XCOM_ORDER_HEADER returns one record
    when s_in_cust_id IS NULL and h_in_cust_id IS NOT NULL then 3
    ELSE 4 end rule_id,
    i.*
    (SELECT c.in_cust_id,
                 s.*, (with alias of course eg. s_...)
                h.*, (with alias of course  e.g. h_...)
    from  in_cust_id_query c
      LEFT JOIN SUPPLY_ORDER s
       on (c.in_cust_id = s.in_cust_id)
    LEFT XCOM_ORDER_HEADER h
      on (c.in_cust_id = h.in_cust_id) i;I hope you get it.
    Of course you can do what you probable currently do. Open both cursors one by one and compare the results. But when you have 10000 in_cust_ids you start 20000 queries and you have a lot of code.
    This method I'm showing need these roles coded as well, but you'll have ONE single query and that will be as fast as ORACLE can be. And I believe it's easier to read too. (But not simple!)
    If you need more help, try to supply an example we can work on.
    -- andy

  • Delete duplicate records based on condition

    Hi Friends,
    I am scratching my head as how to select one record from a group of duplicate records based upon column condition.
    Let's say I have a table with following data :
    ID   START_DATE   END_DATE    ITEM_ID     MULT    RETAIL            |                      RETAIL / MULT
    1     10/17/2008   1/1/2009     83     3     7                 |                            2.3333
    2     10/17/2008   1/1/2009     83     2     4                 |                            2
    3     10/17/2008   1/1/2009     83     2     4                 |                            2
    4     10/31/2008   1/1/2009     89     3     6                 |                            2
    5     10/31/2008   1/1/2009     89     4     10                |                            2.5
    6     10/31/2008   1/1/2009     89     4     10                |                            2.5
    7     10/31/2008   1/1/2009     89     6     6                 |                            1
    8     10/17/2008   10/23/2008     124     3     6                 |                            2From the above records the rule to identify duplicates is based on START_DATE,+END_DATE+,+ITEM_ID+.
    Hence the duplicate sets are {1,2,3} and {4,5,6,7}.
    Now I want to keep one record from each duplicate set which has lowest value for retail/mult(retail divided by mult) and delete rest.
    So from the above table data, for duplicate set {1,2,3}, the min(retail/mult) is 2. But records 2 & 3 have same value i.e. 2
    In that case pick either of those records and delete the records 1,2 (or 3).
    All this while it was pretty straight forward for which I was using the below delete statement.
    DELETE FROM table_x a
          WHERE ROWID >
                   (SELECT MIN (ROWID)
                      FROM table_x b
                     WHERE a.ID = b.ID
                       AND a.start_date = b.start_date
                       AND a.end_date = b.end_date
                       AND a.item_id = b.item_id);Due to sudden requirement changes I need to change my SQL.
    So, experts please throw some light on how to get away from this hurdle.
    Thanks,
    Raj.

    Well, it was my mistake that I forgot to mention one more point in my earlier post.
    Sentinel,
    Your UPDATE perfectly works if I am updating only NEW_ID column.
    But I have to update the STATUS_ID as well for these duplicate records.
    ID   START_DATE   END_DATE    ITEM_ID     MULT    RETAIL    NEW_ID   STATUS_ID |   RETAIL / MULT
    1     10/17/2008   1/1/2009     83     3     7         2         1      |     2.3333
    2     10/17/2008   1/1/2009     83     2     4                                |     2
    3     10/17/2008   1/1/2009     83     2     4           2         1      |     2
    4     10/31/2008   1/1/2009     89     3     6           7         1      |     2
    5     10/31/2008   1/1/2009     89     4     10          7         1      |     2.5
    6     10/31/2008   1/1/2009     89     4     10          7         1      |     2.5
    7     10/31/2008   1/1/2009     89     6     6                            |     1
    8     10/17/2008   10/23/2008     124     3     6                            |     2So if I have to update the status_id then there must be a where clause in the update statement.
    WHERE ROW_NUM = 1
      AND t2.id != t1.id
      AND t2.START_DATE = t1.START_DATE
      AND t2.END_DATE = t1.END_DATE
      AND t2.ITEM_ID = t1.ITEM_IDInfact the entire where_ clause in the inner select statement must be in the update where clause, which makes it totally impossible as T2 is persistent only with in the first select statement.
    Any thoughts please ?
    I appreciate your efforts.
    Definitely this is a very good learning curve. In all my experience I was always writing straight forward Update statements but not like this one. Very interesting.
    Thanks,
    Raj.

  • ISE posture based upon switch user is connected to

    OK, I am a new ISE user and definitely an early beginner on creating ISE policies. I have successfully created a policy that can determine if you are using a corporate asset or not and using 802.1x authentication grant you access to corporate resources or not. This policy also assigns the VLAN the user is placed into. Seems to work quite well so far at least as a baby step in policy creation.
    Our building has different VLANS based upon floors and the like and I would like the policy(s) take this into consideration when assigning the VLAN. Is there a way to include which switch the postureing process is flowing through to assist in assigning the VLAN? I am thinking I would have separate policies based upon the switch / stack but not sure how to include that in the logic. I figured it would be similar to my policy where I check corporate assets and that you are wireless and that you have a valid AD account but have been unable to figure out the endpoint part. I have created network groups for my network devices but am stumped after that. Is there something else I should or could be doing instead? Do I need a completely different train of thought?    
    Brent

    Hello Brent, using "Network Device Groups" can definitely make this possible for you. For instance, you can create a "Location" based group hierarchy that looks like something like this:
    All Locations > HQ > Floor-1
    All Locations > HQ > Floor-2
    All Locations > DR > Floor-1
    etc
    Then you can reference that group in your authorization policy by using something like this
    If "Conditions > Device > Location" = All Locations > HQ > Floor-1
    then
    Permissions = "HQ_Floor-1-Posture"
    If "Conditions > Device > Location" = All Locations > HQ > Floor-2
    then
    Permissions = "HQ_Floor-2-Posture"
    I hope this helps and addresses your issue. 
    Thank you for rating helpful posts!

  • Data Selection for report based upon a 'Prompt Value'

    I want to report information in my report based upon a 'user input prompt value'
    for example:
    'Enter Shareholder Selection - A-Active, I-Inactive, B-Both Active and Inactive'
    if the user enters 'A', the report selects only active shareholders
    if the user enters 'I', the report selects only inactive shareholders
    if the user enters 'B' the report selects all shareholders, active and inactive
    the field in the database that this based upon is their total share value.
    if this field is greater than zero (>0) they are considerd 'active'
    if this field is equal to zero (=0) they are considered 'inactive'.
    I have tried creating some type of filter,  but am not having any luck. 
    I saw a few examples within the forums that I have tried without any luck....unfortunately most of the examples I've seen are base one only two choices.
    I'm sure I need to create some type of 'independant varible' but am not sure how to do that either.
    Any suggestions would be appreciated.
    Thanks.

    Hi Daryl,
    I Tried this unsuccessfully in DESKI . We can't Eliminate Rows having Empty Measure Values or Measure with 0 as values using Table Level Filter as FIlter can't FIlter rows based on Prompt value selection dynamically. Filters filter rows at a time and not based on 3 condition as Active, Inactive and Both. thus filters are of no use.
    I Tried this in WEBI, and it is working perfectly you donu2019t have to create any Object in Universe, you can do it using function UserResponse() at report level.
    Hence if you are comfortable using WEBI for Generating this report then Follow the steps.
    1. Create Report With Name and Shares Object. It will display all Shareholder Names and No.of shares they hold.
    2. Use Status Object in Query filter, use condition as u201CEqual Tou201D and Select prompt. It  contains Active, Inactive and Both as values.
    3. Report will Display all Shareholder names and No. of  shares  like 45, 789, 0, 4562 where 0 is inactive Shareholder and all other are active shareholder.
    4. Create Variable using Formula.
    =If(UserResponse("Enter Status:")="Active" And [Shares]>0;[Shares];If(UserResponse("Enter Status:")="Inactive" And [Shares]<=0;[Shares];If(UserResponse("Enter Status:")="Both";[Shares])))
    5. Remove Shares Object from the report and Put Variable created with Names of Shareholders.
    6. Select Table-> Properties-> Display-> Uncheck the Option u201CShow Rows with Empty Measure Valuesu201D
    7. Report will display Value correctly as per your Prompt value selection.
    I Hope this Helpsu2026
    Thanksu2026
    Pratik

  • How to stop workitem complete or how to keep work item in inbox based on conditions even if it completed

    Hi,
    my requirement is to call webdyn pro screen from workflow..
    i am calling webdynpro screen by using FM :CALL_BROWSER from workflow.
    when webdyn pro screen is called user will enter some values . if user closed webdyn pro screen with out entering any values we need show this workitem in his inbox. so that user can again open it and enter values in the webdyn pro screen.
    Please help how to stop work item complete based on conditions.
    Thanks,
    phani

    Hi,
    As per my understanding, this is not a proper approach toy call web dynpro using FM CALL_BROWSER. is the web dynpro screen being called when user clicks on the work item from portal UWL OR from SAP SBWP ?
    if you are calling web dynpro screen from portal UWL when user clicks on work item link, better you achieve it using SWFVISU tcode. in SWFVISU tcode you can maintain which web dynpro. application to call when particualr work item task come in user's inbox. in your web dynpro code, then you can write your buisiness logic when user clicks for example SUBMIT/SAVE button. on action submit/save button you can use FM SAP_WAPI_WORKITEM_COMPLETE to complete the worktiem once the user clicks on final submit/save button. in this way the workitem will get removed from user inbox only upon clicking on submit/save button.
    You can refer below link for web dynpro for workitem:
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/70648e99-4cc1-2c10-879d-9c61003c69d6?QuickLink=index&…

Maybe you are looking for

  • Is it possible to create a custom display type in DIAdem, for example a speedomete​r type instrument​?

    As an example I have velocity data which shows a vehicle accelerating from rest to 60 km/h and then travelling at a constant speed. As opposed to displaying this data using a 2D axis system is it possible to create a new speedometer display type to d

  • Installing Flash player doesn't finish Step 3 Prompt to buy another product

    Installing Flash player, after completing Step 2, I'm prompted to buy other products, which I don't want to do.  Anybody have a link that actually completes all steps? Safari browser is not loading pages.  Need help asap.  Thanks! 

  • ITunes-Icon on iPhone-6 is missing

    The iTunes-Icon (2 music-notes in a white circle within a pink-purple square) is missing on my iPhone. Maybe I've it  inadvertently erased. I can't find it in the app-store. Has anyone any idea how to get it back?  Thanks in advance.

  • Open all html pages in one window w/button

    I'm trying to figure out how to have all of my pages for my site open under one browser window instead of opening up a new window when each button is clicked. I built Flash buttons for the pages and they work fine...they just open up the pages in ind

  • Integrate SAP XI+JAVA+SAP CRM

    Hi @SAP i have an existing J2EE based crm which have to use sap xisap crmexisting j2ee application . is it possible to intergate the following technologies if not give a alternate solution for this waiting for eariliest reply bye jagan