Set flag for a set of records

Hi
I have a table that stores requests raised by employees as below
name Request_ID date status
ABC 112 05-Dec-11 rejected
ABC 786 06-Dec-11 approved
ABC 987 07-Dec-11 rejected
ABC 119 08-Dec-11 approved
MNP 221 09-Nov-11 rejected
MNP 666 10-Nov-11 approved
MNP 221 11-Nov-11 rejected
MNP 999 12-Nov-11 approved
RST 99 23-Dec-11 rejected
RST 101 24-Dec-11 approved
RST 876 25-Dec-11 rejected
RST 127 26-Dec-11 approved
I need to check the status of the latest request of each employee and set the flag of all his requests as -
‘A’ if the latest request status is ‘approved’
‘B’ if the latest request status is ‘rejected’
The resultset should be something like -
name Request_ID date status Flag
ABC 112 05-Dec-11 rejected A
ABC 786 06-Dec-11 approved A
ABC 987 07-Dec-11 rejected A
ABC 119 08-Dec-11 approved A
MNP 221 09-Nov-11 rejected B
MNP 666 10-Nov-11 approved B
MNP 221 11-Nov-11 approved B
MNP 999 12-Nov-11 rejected B
RST 99 23-Dec-11 approved A
RST 101 24-Dec-11 approved A
RST 876 25-Dec-11 rejected A
RST 127 26-Dec-11 approved A
Could you please help me in framing this SQL. Use of any analytical function would be helpful
Regards
-pankaj

Hi, Pankaj,
Welcome to the forum!
910543 wrote:
Hi
I have a table that stores requests raised by employees as belowWhenever you have a problem, please post CREATE TABLE and INSERT statements for your sample data, so that the people who want to help you can re-create the probelm accurately and test their ideas. since this is your first message, I'll do it for you:
CREATE TABLE     table_x
(     name           VARCHAR2 (5)
,     request_id     NUMBER
,     dt          DATE          -- DATE is not a good column name
,     status          VARCHAR2 (10)
,     CONSTRAINT  x_uk     UNIQUE (name, dt)
INSERT INTO table_x (name, request_id, dt, status) VALUES ('ABC', 112, TO_DATE ('05-Dec-2011', 'DD-Mon-YYYY'), 'rejected');
INSERT INTO table_x (name, request_id, dt, status) VALUES ('ABC', 786, TO_DATE ('06-Dec-2011', 'DD-Mon-YYYY'), 'approved');
INSERT INTO table_x (name, request_id, dt, status) VALUES ('ABC', 987, TO_DATE ('07-Dec-2011', 'DD-Mon-YYYY'), 'rejected');
INSERT INTO table_x (name, request_id, dt, status) VALUES ('ABC', 119, TO_DATE ('08-Dec-2011', 'DD-Mon-YYYY'), 'approved');
INSERT INTO table_x (name, request_id, dt, status) VALUES ('MNP', 221, TO_DATE ('09-Nov-2011', 'DD-Mon-YYYY'), 'rejected');
INSERT INTO table_x (name, request_id, dt, status) VALUES ('MNP', 666, TO_DATE ('10-Nov-2011', 'DD-Mon-YYYY'), 'approved');
INSERT INTO table_x (name, request_id, dt, status) VALUES ('MNP', 221, TO_DATE ('11-Nov-2011', 'DD-Mon-YYYY'), 'rejected');
INSERT INTO table_x (name, request_id, dt, status) VALUES ('MNP', 999, TO_DATE ('12-Nov-2011', 'DD-Mon-YYYY'), 'approved');
INSERT INTO table_x (name, request_id, dt, status) VALUES ('RST',  99, TO_DATE ('23-Dec-2011', 'DD-Mon-YYYY'), 'rejected');
INSERT INTO table_x (name, request_id, dt, status) VALUES ('RST', 101, TO_DATE ('24-Dec-2011', 'DD-Mon-YYYY'), 'approved');
INSERT INTO table_x (name, request_id, dt, status) VALUES ('RST', 876, TO_DATE ('25-Dec-2011', 'DD-Mon-YYYY'), 'rejected');
INSERT INTO table_x (name, request_id, dt, status) VALUES ('RST', 127, TO_DATE ('26-Dec-2011', 'DD-Mon-YYYY'), 'approved');
COMMIT; name Request_ID date status ...If those are all the columns in the table, and you want to display a flag column, you can do something like this:
SELECT     name
,     request_id
,     dt
,     status
,     CASE  FIRST_VALUE (status) OVER ( PARTITION BY  name
                           ORDER BY     dt     DESC
          WHEN  'approved'     THEN  'A'
          WHEN  'rejected'     THEN  'B'
     END          AS flag
FROM     table_x
;If the table has a flag column, and you need to populate it, you can use the query above in a MERGE statement. (You may be better off not actually storing the flag, however, if it's hard to keep up to date.)
MNP 221 09-Nov-11 rejected
MNP 666 10-Nov-11 approved
MNP 221 11-Nov-11 rejected
MNP 999 12-Nov-11 approved ...
I need to check the status of the latest request of each employee and set the flag of all his requests as -
‘A’ if the latest request status is ‘approved’
‘B’ if the latest request status is ‘rejected’
The resultset should be something like -
name Request_ID date status Flag
MNP 221 09-Nov-11 rejected B
MNP 666 10-Nov-11 approved B
MNP 221 11-Nov-11 approved B
MNP 999 12-Nov-11 rejected BIn the original data, the status for the row with request_id=999 was 'approved'. Is there a typo somewhere?
Edited by: Frank Kulash on Jan 26, 2012 10:57 PM

Similar Messages

  • Prerequisites required to set Deletion Flag for an Order

    Hi Experts,
    I need to know what are all the Prerequisites required to set Deletion flag for an Order.
    i.e. can i set deletion flag for any existing order?
    Kavin

    Hi Kevin,
    System will allow you to set deletion flag if,
    - No Goods Movement is carried out.
    - No Confirmation has has been carried out.
    - Conclusion of point 1 and 2 is order should not carry any cost.
    - If In process Inspection is active then Result Recording should be not started.
    - In case of Process Order CRCR (Control Recipe Created) status is not allowed.
    Regards,
    Dhaval

  • How to Set up HTTPOnly and SECURE FLAG for session cookies

    Hi All,
    To fix some vulnerability issues (found in the ethical hacking , penetration testing) I need to set up the session cookies (CFID , CFTOKEN , JSESSIONID) with "HTTPOnly" (so not to access by other non HTTP APIs like Javascript). Also I need to set up a "secure flag" for those session cookies.
    I have found the below solutions.
    For setting up the HTTPOnly for the session cookies.
    1] In application.cfc we can do this by using the below code. Or we can do this in CF admin side under Server Settings » Memory Variables
         this.sessioncookie.httponly = true;
    For setting up the secure flag for the session cookies.
    2] In application.cfc we can do this by using the below code. Or we can do this in CF admin side under Server Settings » Memory Variables
         this.sessioncookie.secure = "true"
    Here my question is how we can do the same thing in Application.cfm?. (I am using ColdFusion version 10). I know we can do this using the below code , incase of HTTPOnly (for example).
    <cfapplication setclientcookies="false" sessionmanagement="true" name="test">
    <cfif NOT IsDefined("cookie.cfid") OR NOT IsDefined("cookie.cftoken") OR cookie.cftoken IS NOT session.CFToken>
      <cfheader name="Set-Cookie" value="CFID=#session.CFID#;path=/;HTTPOnly">
      <cfheader name="Set-Cookie" value="CFTOKEN=#session.CFTOKEN#;path=/;HTTPOnly">
    </cfif>
    But in the above code "setclientcookies" has been set to "false". In my application (it is an existing application) this has already been set to "true". If I change this to "false" as mentioned in the above code then ColdFusion will not automatically send CFID and CFTOKEN cookies to client browser and we need to manually code CFID and CFTOKEN on the URL for every page that uses Session. Right???. And this will be headache.Right???. Or any other way to do this.
    Your timely help is well appreciated.
    Thanks in advance.

    BKBK wrote:
    Abdul L Koyappayil wrote:
    BKBK wrote:
    You can switch httponly / secure on and off, as we have done, for CFID and CFToken. However, Tomcat automatically switches JsessionID to 'secure' when it detects that the protocol is secure, that is, HTTPS.
    I couldnt understand this. I mean how are you relating this with my question.
    When Tomcat detects that the communication protocol is secure (that is, HTTPS), it automatically switches on the 'secure' flag for the J2EE session cookie, JsessionID. Tomcat is configured to do that. Coldfusion has no say in it. So, for JsessionID, 'secure' is automatically set to 'false' when HTTP is detected and automatically set to 'true' when HTTPS is detected.
         If this is the case then why I am getting below info for jsessionid (As you mentioned it should set with SECURE flag . Right???). Note that we are using web server - Apache vFabric .And the application that we are using is in https and there is no hit is going from https to http.
    Name:
    JSESSIONID
    Content:
    782BF97F50AEC00B1EBBF1C2DBBBB92F.xyz
    Domain:
    xyz.abc.pqr.com
    Path:
    Send for:
    Any kind of connection
    Accessible to script:
    No (HttpOnly)
    Created:
    Wednesday, September 3, 2014 2:25:10 AM
    Expires:
    When the browsing session ends
    BKBK wrote:
    2]When I checked CF Admin->Server Settings->Memory Variables I found that J2EE SESSION has been set to YES. So does this mean that do we need to set HTTPOnly and SECURE flag for JSESSIONID only or for CF session cookies (CFID AND CFTOKEN ) as well ?.
    Set HTTPOnly / Secure for the session cookies that you wish to use. Each cookie has its pros and cons. For example, the JsessionID cookie is more secure and more Java-interoperable than CFID/CFToken but, from the explanation above, it forbids the sharing of sessions between HTTP and HTTPS.
         I understood that setting thos flags (httponly/secure) is as per my wish. But my question was , is it necessary to set those flags forcf session cookies (cfid and cftoken) as we have enabled J2EE session in CF admin?. Or in other way as the session management is J2EE based do we need to set those flags for CF session cookies?.
    BKBK wrote:
    3]If I need to set HTTPOnly and SECURE flag for JSESSIONID , how can I do that.
    It is sufficient to set the HTTPOnly only. As I explained above, Tomcat will automatically set 'secure' to 'true' when necessary, that is, when the protocol is HTTPS.
         I understood that it is sufficient to set httponly only.but how we will set it for jsessionid?. This is my question. Apache vFabric will alos set secure to true automatically. Any idea??

  • ESB Process reads a Batch file for a limited set of records only..?

    Dear All,
    I am having an ESB process that reads a Batch file (csv) that has around 10,000 Products information.
    I have another BPEL process that will create the Product in Oracle Apps through standard API (Main BPEL process that calls a child process for creating product).
    I am invoking the BPEL process from ESB, and that works fine.
    Now, the Issue is: I am able to create at a time around 10 Products (the main process calls the child process in a loop.). The main process instance is not getting created but the child process instance is getting created for a set of records, afterwards the child process instances get stops creating. The main process instance could not be found in the console. Not getting why the process is not getting visible as well it is not completing the process.
    What could be the problem for this... Am I need to change any environment configurations...?
    Please update...
    Many Thanks in advance...

    Does this apply to you?
    https://social.technet.microsoft.com/Forums/en-US/9ccd8e50-b0af-4f58-9787-6435834e4c52/dfsr-not-working-on-new-windows-2008r2-server
    Thanks for the link, but no - not the same scenario although the error is the same.   The RGs I'm working with are all in sync and communication is working, it's just getting the backlog reported correctly.
    To reiterate, I can paste two versions of the exact command into the DOS window buffer; one copied from OneNote and one copied from my batch file.  Executing the one from OneNote succeeds and reports the RG in sync and the one copied from the batch
    file fails.
    I can repeat the results by up arrow once to the command pasted into the buffer from the batch file and see it fail.  Then up arrow twice to retrieve the command pasted from OneNote into the buffer and it will report correctly (illustrated in the grahic).
    Let me add that the command in the batch file was originally copied from OneNote and pasted in to the batch file; as if going into the batch file somehow corrupts it.
    - a -

  • Setting deletion indicator/Flag for an operation in production order

    Dear All, Hi
                     How to set deletion indicator/flag for an operation in a production order. I don't want to delete the operation as such. Please help & suggest.
    Ragards,
    Shaiz

    Hi Shaiz,
    I hope the requirement is just like you posted earlier as in case of component deletion.
    Here in this case also the behaviour of the order remains the same.
    So you can go for release the order as soon as the order gets created, your both the requirements can be fullfilled.
    Also you havn't provided the exact feedback on the solutions offered by all of us, on your last query.
    Request you to give detailed input on the same.
    Hope thish helps you.
    SmanS

  • Set Deletion Flag for the Preventive Maintenance Order

    Hi,
    I need to set the Deletion flag for the Service Order. Deletion flag available in the screen disabled. Please suggest.
    also I need know under which I shall be able to set such deletions.
    Thank you,
    Vijaya

    Hi Vijaya,
    Pls refer the help.sap.com related to deletion flag for PM/CS Orders. Some of the check criteria mentioned below for your reference.
    Before a deletion flag is set, the following requirements must be met:
    u2022 Any manually added purchase requisitions or purchase orders for the order must be deleted first.
    The balance of the actual costs for the order must be zero. This means that the deletion flag can only be activated if the order has already been settled, or if no actual costs were incurred for the order.
    u2022 Commitments relating to the order must be deleted.
    u2022 Unprocessed and incorrect goods movements must be processed.
    When the deletion flag is activated, all remaining capacity requirements are deleted. A deletion indicator is also set in any open material reservations.
    An order that has been flagged for deletion cannot be changed. However, you can cancel the deletion flag.
    Thanks
    Siva
    Edited by: sivakumar kasi on Sep 3, 2009 12:09 PM
    Pls set the Order as Techically completed (TECO) and check the deletion flag set.
    Thanks
    Siva

  • Setting the 'reportable' flag for a very large ODS

    Hello Community,
    I am working on a very large BW system (6 Tb), and we recently have the need to set the 'BEx Reporting' flag on some very large ODS objects.
    It was my impression that setting this flag would be easy to do.  But the transport that contains this flag for six large ODS objects has already been running for more than 16 hours.
    Can you tell me, what actually happens in the database when the 'BEx Reporting' flag is turned on for an ODS ?
    Thanks !
    Keith

    Hello Bhanu,
    Thanks for the quick response.  Are you able to provide some more information ?
    are the SID values created in a new SID table ?
    if the ODS was already very large, then would you expect the new SID table to also be very large ?
    what about the case if a SID value already exists for the characteristic ?
    Thank you !
    Keith

  • Set the final invoice flag for a purchase order

    I want to know how to set the final invoice flag for a purchase order.
    I tried BAPI_PO_CHANGE but it is giving me error.
    Help me.

    Hi,
    I think ur BW report shows the cleared Invoice no. The second invoice no. might not have been extracted to BW system. Check your order no. in Cube whether it has two invoice nos.
    Regards,
    Suman

  • Standard/Custom program to set deletion flag for Purchase Requistions

    Hi all,
    If any of you know the Standard/Custom program to set deletion flag for purchase requistions, please let me know. It would be of great help.
    Thanks in advance,
    Karthik

    Hello
    Bapi BAPI_REQUISITION_DELETE will help you.

  • Cannot set deletion flag for order

    Dear Experts,
    I am trying to set deletion flag for order XXXX,
    i am getting Error Massage " You cannot set deletion flag for order XXX (see log) Message no. CO432"
    my order status is REL  CNF  DLV  PRC  GMPS MACM OPGN SETC
    How can i set deletion flag for order.....
    Please give your suggestion.
    Thanks for support.......

    Dear,
    Order status is REL CNF DLV PRC GMPS MACM OPGN SETC
    And, I have checked log u201CThere are no entries in the deletion flag logu201D
    There no balance- I have not done any confirmation (Total Qty 1000 EA, Delivered Qty 0 EA)
    You have done confirmation and delivery has happened thats why the status shows "CNF & DLV" You need to complete your settlement.
    Check and revert back.
    Regards,
    Alok Tiwari

  • Set deletion flag for Order before releasing the order

    Hi all,
    can we set the Deletion Flag for an order before release of that order.
    Regards,
    Bhanu.

    Hi,
    You can lock and unlock order without releasing.
    In case of Un execute we can not release order further.
    Path:
    ORDER-FUNCTION-LOCK
    order-function-unlock
    Regards,
    Sudhakar

  • How to mass set deletion flag for the production order

    Hi Expert,
      do you know which transcation code or program is used to mass set the deletion flag for production order?
    thank you in advance!

    Hi,
    http://www.sap-img.com/production/how-to-delete-old-production-orders.htm
    Note that CO78 is the start of the Archive process.  We are not using Archiving yet but the initial process fits the bill for what we need to do as mentioned in the original note.
    Decide the range of orders you want to delete.  This range will be used in the program variant. Note that we will be running CO78 many times because of the number of orders involved. 
    Running CO78 calls program PPARCHP1 and this involves the use of a Variant where the parameters for selection etc. are set. 
    First of all, create the variant via SE38 for PPARCHP1. 
    Enter details for number range, order type, plant and set deletion flag. Flag Detailed log and set this to go to Spool when running. Save the variant. You can also force the job to run in background at this point (which I would recommend) via menu line Variant --> Attributes.  Also here you can flag order number, order type and plant to be required fields. 
    Run CO78
    Press the first button - deletion flag/deletion indicator.
    Choose the variant you have just created.  Press "Maintain" to update the selection range on subsequent runs. Save changes and return to initial screen.
    Press Start date to set date and time for job to run as per any background job. Icon will turn Green.
    Press Spool Params to set save output in Spool Q rather than print immediately. Icon will also turn Green.
    Press Execute and job can be tracked via SM37.
    Details of deleted orders and errors will appear in the Spool.
    Rerun as many times as you need with relevant order ranges till all required orders are deleted.
    Hope this will resolve your issue.
    Regards,
    Naveen.

  • Set the Unicode check flag for all programs.

    Hello friends,
    We are now upgrading our ecc6 system to unicode. The problem is that all our programs
    are not flaged for unicode checks and there for have syntax errors. I now how to mark
    this flag for a single program but how can I do it to all programs?
    I realy need your help.
    Thanks in advance,
    Gershon.

    Hi Gershon,
    In general, transaction  UCCHECK is designed to cover all Unicode adaptations needed. The guide called
    u201CRequirements of ABAP Programs in Unicode Systemsu201D, which can be found via:
    http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b02d3594-ae48-2a10-83a7-89d369b708e5
    gives customers a comprehensive description of possible errors. Please also have a look at the docu provided directly in transaction UCCHECK. In addition, SAP notes 1322715 (search for UCCHECK) and 1319517 (point 8.) might be helpful.
    Please note that customer programs have to be adapted - simply setting the Unicode flag works only for the objects with a green traffic light in UCCHECK .
    Best regards,
    Nils Buerckel
    SAP AG

  • SETTING DELETION FLAG FOR PRODUCT COST COLECTOR:

    Hi Gurus, could you please help me with this question:
    We need to turn off the repetitive mfg
    indicator active for a group of materials. this in order to replace product collectors to production
    orders.
    When I tryed to set the deletion flag for product cost colectors, SAP
    Shows this message :
    "THERE ARE STILL UNSETTLED VARIANCES FOR ORD 710040".
    Cheking Note "421710 - Check report whether "Deletion flag" status can
    be set" I found the program COPC_COSTOBJ_REORGCHECK , this program
    shows that I have Unsettled variances since 2004...
    The order have a settlement rule PER, So I can't settle 2004
    variances.. checking the note 421710, I Found that other way is to turn
    off the field indicator "variance to costing-base PA" in OK07.
    Must I turn off the field "variance to costing-base PA" temporaly, in order to close de cost colectors ?
    there are another program or report that I can use in order to settle the old variances?
    Message was edited by:
            Andres Moreno

    REWARDED POINTS AVAILABLE  !!!!!!

  • Set Mass Deletion Flag for production orders

    Hi,
    I am planning to set mass deletion flag for production orders using programme PPARCHP1.
    My users dont have access to SE38/SA38 and they cant run this program from directly.
    I dont wnat my users to do this preprocessig using SARA or CO78 as it will give access to them for whole archiving process + it only works in background.
    I am thinking to create a Z tocde for this program and use it in dialogue mode also. Do you guys see any aftereffects with this process?
    Let me know if creating a Z tocde sounds a good idea?
    Edited by: santosh sarda on Mar 10, 2011 3:23 AM
    Edited by: santosh sarda on Mar 10, 2011 3:28 AM

    The standard SAP procedure to set the archive is that
    - you run COAC in background to set deletion flag and deletion indicator.   It should be set as the variant and run periodically (i.e., monthly). 
    - The system get all orders with DLV status in the past xx days depending on your variant to set deletion flag. 
    - Also it will change the status DLFL to DLT based on your residence time 1. 
    - The orders with DLT that reside in system longer than residence time 2 then archive.
    This should be done by IT department or background jobs.  Not the users.
    Which, in my opinion, is enough.  However, if you do need the user to select by themselves which orders they want to set deletion flag (why is that?).  Then you may want to explore enhancement. 
    For the sake of simplicity, I will recommend to use user status (normal cohv can change that, as we know; therefore no new fancy screen needed).  Then develop the user exit to set deletion indicator in PPCO0002 - EXIT_SAPLCORE_001 based on user status.  The rest of the procedure should remain the same.
    If you want to allow user to do every steps and develop some Z* screen for users, they must have the authorization for archiving anyway.  They just don't have the t-code COAC, and SARA.  In my opionion, it is overkill.  Plus in terms of users, I don't think they have skills enough if there is some errors during archiving (i.e., logical file error, etc.).
    Hope it helps.

  • IMAP setting flags for DSN message problem

    Hi,
    I have a question about processing DSN flags using Java Mail.
    We are trying to set SEEN and FLAGGED flags also for DSN messages (for any other messages it is working perfectly fine).
    The problem is that no flags are set, no IMAP commands are issued.
    For any 'normal' messages the IMAP command is issued (for example: A27 STORE 13 +FLAGS (\Seen)).
    We are using Exchange Server 2007 with IMAP support enabled on the mailbox.
    The strange thing is that i can manualy set SEEN and FLAGGED flags from Outlook on this DSN message and then print flags for this message from Java Mail.
    Is there any standard for FLAG processing for DSN messages? Is this a problem in Java Mail / Exchange or some limitation? As I believe DSN in also a javax.mail.Message from the implementation point of view...
    Regards

    Hi Bill,
    This was a good point, about calling setFlags method on the wrong message.
    The problem is because, we are dealing with Exchange bug described here:
    BODYSTRUCTURE with "multipart" "signed" not parsing
    and using workaround described here:
    http://www.oracle.com/technetwork/java/faq-135477.html#imapserverbug
    However, we were setting flags on message created using following code
    SharedByteArrayInputStream bis =  new SharedByteArrayInputStream(bos.toByteArray());
    MimeMessage cmsg = new MimeMessage(session, bis);not on original message from the mailbox.
    Regards

Maybe you are looking for

  • A few questions on setting up the system...

    Well, I'm new to Arch coming from Slackware, and I'm enjoying it so far, except for some things. For one, I finally got X working, but I'm not sure how I should configure /etc/modprobe.conf to load the modules agpgart and intel-agp. Second, I know of

  • ProSelect no longer allowed access to Lr catalog (ver. 3.0+)

    It appears that Adobe have changed the  functionality of Lightroom 3 so that it is no longer possible to open  Raw images in Lightroom 3 from ProSelect (any version). Previous versions of Lightroom allowed ProSelect to pass a list of  image file loca

  • DOUBT IN CRETAING DATAFILES

    Hello, i have one doubt in creating datafile if suppose i have created a TABLESPACE T1. with DATAFILE X. CREATE TABLESPACE T1 DATAFILE 'D:\ORACLE\ORADATA\ORCL\X1.DBF' SIZE 1024M Now if suppose that i wan't to increase the tablespace size fot that i h

  • Compilation options native libraries

    I keep getting a number of errors due to compilation issues. The problem I have is that the compilations of the vi finds other versions of subvi's in old libraries and not the ones under the labview subdirectory. If I go through and find these and th

  • Broken indexes ??

    I am currently running an environment of 4 SunONE directory servers (version 5.2 SP3) on Fujitsu hardware and Solaris 8 operating system. There are 2 masters (using multi-master replicatoin) and 2 query servers. Before I started anything, the 2 maste