Select or update a field based on a column on another row

hi
I have some 5000 rows for the following combination of columns. Each combination has two rows. The only difference between these two rows is an indicator field. If one row for the same combination is having indicator as 'M' the other row for the same combination should ideally have indicator 'R'. But unfortunately the other row's indicator is null.
ie. if the first row for same combination of fields, indicator is 'M. then other one is null which should have been 'R'. If the first row is 'R' then other one is again null which should have been 'M'.
PRODUCT_NO STATE MONTH INDICATOR
1001 CA SEPT M
1001 CA SEPT null
1002 NY OCT R
1002 NY OCT null
Here for the first combination indicator is M and other one is null. But i need to update it to 'R' since other rows is M.
Same way for second combination first row is R second row then should have M as indicator.
Basically it is changing field to a value based on the value in the other rows indicator for the same combination of the above columns.
Please help if anybody has idea to do this in simple steps
Thanks

Is this what you are looking for?
WITH TABLE_A AS
SELECT  '1001' PRODUCT_NO, 'CA' STATE,  'SEPT' MONTH,  'M' INDICATOR FROM DUAL  UNION ALL
SELECT  '1001' PRODUCT_NO, 'CA' STATE,  'SEPT' MONTH,  null  INDICATOR FROM DUAL  UNION ALL
SELECT  '1002' PRODUCT_NO, 'NY' STATE,  'OCT' MONTH,  'R' INDICATOR FROM DUAL  UNION ALL
SELECT  '1002' PRODUCT_NO, 'NY' STATE,  'OCT' MONTH, NULL INDICATOR FROM DUAL UNION ALL
SELECT  '1003' PRODUCT_NO, 'LA' STATE,  'NOV' MONTH,  'R' INDICATOR FROM DUAL  UNION ALL
SELECT  '1003' PRODUCT_NO, 'LA' STATE,  'NOV' MONTH, 'M' INDICATOR FROM DUAL
SELECT
PRODUCT_NO,
STATE,
MONTH,
DECODE(A.INDICATOR,NULL,(SELECT DECODE(B.INDICATOR,'R','M','R')  FROM TABLE_A B WHERE B.PRODUCT_NO = A.PRODUCT_NO AND B.STATE = A.STATE AND B.MONTH = A.MONTH AND B.INDICATOR IS NOT NULL), A.INDICATOR) INDICATOR
FROM
TABLE_A A

Similar Messages

  • Get values in dropdown field based on f4 help in another field

    Hi Experts,
    How to Get values in dropdown field based on another field which is F4 Help. If I select one value in f4 help field(ex: 1) I need to get values in dropdown field (ex:a, b, c),If I select another value in f4 help (ex:2) I need to populate different values (ex: d). Can any one please provide sample code that can help more.
    Thanks,
    Ashok.
    Moderation: Kindly search and find the solution, before you post.

    Dear Ashok,
    You can take help from this program in SAP named BCALV_EDIT_08.
    Thanks.
    With regards.

  • Update multiple rows based on two columns in same row

    I have a 1000 rows in a table I would like to update with a unique value. This unique value is a cocatenation of two columns in teh same row.
    Each row has a (i) date and a (ii) time and a (iii) date_time column. I would like to update the date_time (iii) column with a cocatenation of the (i) date and (ii) time columns.
    I know how I would update a single row but how can I update multiple rows with a cocatenation of each of the two columns - i.e put a different value into the date_time column for each row?

    this?
    update table tab_name
    set date_time =date||time
    where your_condition

  • Update a field based on a max select query

    Hi
    I am just learning SQL so apologies if this is simple to you guys.
    I have a table called [Stock WIP Table] which has duplicates in it.  I have an [autonumber] field, a [palletid] field, and a [number5] field.  I have the select query working to show the most recent record for each palletID:
    SELECT
    PalletID,MAX(autonumber)
    FROMdbo.[Stock
    WIP Table]
    GROUPBYPalletID
    How do I get the query to now delete all rows that are not in the select query?
    Alternatively how could I add update the [number5] field to '1' where the [autonumber] is in the select and I can  then delete all records that do not contain a '1' in [number5]
    Can anyone help?
    Thanks
    AJ

    Hi
    I am just learning SQL so apologies if this is simple to you guys.
    I have a table called [Stock WIP Table] which has duplicates in it.  I have an [autonumber] field, a [palletid] field, and a [number5] field.  I have the select query working to show the most recent record for each palletID:
    SELECT
    PalletID,MAX(autonumber)
    FROMdbo.[Stock
    WIP Table]
    GROUPBYPalletID
    How do I get the query to now delete all rows that are not in the select query?
    Alternatively how could I add update the [number5] field to '1' where the [autonumber] is in the select and I can  then delete all records that do not contain a '1' in [number5]
    Can anyone help?
    Thanks
    AJ
    Simply this for the DELETE
    DELETE t
    FROM dbo.[Stock WIP Table]t
    WHERE EXISTS (SELECT 1
    FROM dbo.[Stock WIP Table]
    WHERE PalletID = t.PalletID
    AND autonumber > t.autonumber)
    No need of UPDATE bit value and then deleting. just above will ensure it gets deleted in single step
    another method you may use is this
    DELETE t
    FROM dbo.[Stock WIP Table] t
    CROSS APPLY (SELECT MAX(autonumber) AS MaxID
    FROM dbo.[Stock WIP Table]
    WHERE PalletID = t.PalletID
    )t1
    WHERE t1.MaxID <> t.autonumber
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Having a problem using Workflow to update a field based on ZIP code

    I created a Workflow to update a Yes/No picklist called eligibility based on a Text (Short) field called Applicant ZIP code.
    It's set to update on the Opportunity page:
    Before modified record saved
    And the value function is:
    IIf(InStr("60601_60602",[&lt;stApplicant_Zip_Code_ITAG&gt;|http://forums.oracle.com/forums/]+)&gt;0,"Yes","No")+
    That was a guess of how to try it while relying on my limited MS SQL & Access knowledge.
    It does work correctly using what I did. The problem I have is that I actually need to choose from over 600 ZIP codes. The function window only allows for 256 characters. (And I suspect my way is fairly inelegant for search a multi-thousand character string.)
    Any suggestions?

    I created a Workflow to update a Yes/No picklist called eligibility based on a Text (Short) field called Applicant ZIP code.
    It's set to update on the Opportunity page:
    Before modified record saved
    And the value function is:
    IIf(InStr("60601_60602",[&lt;stApplicant_Zip_Code_ITAG&gt;|http://forums.oracle.com/forums/]+)&gt;0,"Yes","No")+
    That was a guess of how to try it while relying on my limited MS SQL & Access knowledge.
    It does work correctly using what I did. The problem I have is that I actually need to choose from over 600 ZIP codes. The function window only allows for 256 characters. (And I suspect my way is fairly inelegant for search a multi-thousand character string.)
    Any suggestions?

  • Website has many drop-down menus. Once selected, user updates the page based on selections. Unable to select more than 1 option at a time. Is there a setting to fix this? I was able to do before, but after reinstall, it has stopped.

    This occurs on any website with active menu drop-downs. I am able to select the 1st drop-down, but must then load the page and do the next drop-down. I used to be able to make every selection at once and then reload the page to reflect all of those options.

    I have taken it back to the Apple store genius bar, but they say they don't see anything wrong. Well unless you use it all day and experience the problems when they happen, you wont see anything wrong. But there are lots wrong with it. But this would be the same store as I purchased the phone. And they backed up my old Iphone 4, but were not able to get anything to load back onto my new phone. So, I lost pretty much everything. But over time, some of my contacts have started showing up, although i am still missing over 800 of them.

  • WriteBack: Update a field based on two conditions.

    Hi Experts,
    I am facing a serious problem in write back to database.
    Let me explain the writeback i am trying to do.
    I have a table as Below
    Col1----- Col2---------Col3----------Col4
    100--------1-------------2----------100/(1+2)
    Col1,col2,col3 are editable.
    Once the values are entered in these columns Col4 is calculated by the formula (Col1/(Col2+Co3))
    If the user enters 0 in col2 and col3 then it will be a division by zero which i have handled by the DECODE function
    But the user requires a standard value to be shown there that is Col1/0.57895 whenever he enters 0 in col2 and col3.
    I initiially put a column formula for Col4 in answers saying if col2 or col3 = 0 then (Col1/0.57895)
    But as this formula is only at the prsentation level...teh values were not getting saved in the database.
    My requirement is i need to put this condition in the writeback xml itself and see to it that this standard value be updated in the table itself.
    like
    update table set col4=Col1/0.57895 where col2=0 and col3=0
    Update table set col4=(Col1/(Col2+Co3)) where col2 <>0 or col3<>0
    I am unable to use two update queries in teh xml template.
    Please let me know how can i implement this in the xml template.
    Appreciate your immediate response.
    -Best Regards!

    You can't do it in the xml but you can do it in the database with a before trigger update
    http://www.techonthenet.com/oracle/triggers/before_update.php

  • Selection screen validation  - one field based on another field

    Hi all,
    i'm getting Month in Select option and Year in Parameter.
    When i execute the report, it should check whether one is entered without the other one. If so, it should throw error message. 
    How to do this in selection screen ?
    this is what the coding should be...
      if s_month[] is not initial and p_year is initial.
        Message 'Enter Payroll Year' type 'E'.
      endif.
      if s_month[] is initial and p_year is not initial.
        Message 'Enter Payroll month' type 'E'.
      endif.
    But under which event i should write this..
    can anyone pls help me..
    Regards,
    Shanthi

    Hi Shanti,
    Define your selection-screen elements between
    SELECTION-SCREEN BEGIN OF BLOCK <block name>
    Select-options....
    Parameters:
    SELECTION-SCREEN END OF BLOCK <block name>
    You specify ur code in AT SELECTION-SCREEN ON BLOCK <b1>.
    This would help you if either one of the entry is missing...
    And even you can mention in AT SELECTION-SCREEN event...
    But if you have any other parameters there its not necessary for the user to specify if he had entered...
    As month and year are interrelated for your program its better you go for the first procedure ie in BLOCK event.
    Hope this would help you,
    Regards
    Narin Nandivada.

  • Update a Checkbox based on the value of another Checkbox

    We have a business rule that needs to following to happen.
    If the "Commit" checkbox is checked then the "Forecast" checkbox needs to be checked.
    We would like to handle this through workflow. Here is what we have done so far
    Workflow Rule Condition: FieldValue('<bCommit_ITAG>') = 'Y'
    Action: Field to Update - Field Name* is set to Forecast
    Value is set to: [<Forecast>]='Y'
    Thanks for the help

    Brian,
    What you have written should work, try Value is set to: <Forecast>=Yes.
    This should also be created in the Administration section as its not web services but workflows, you'll get better responses.
    cheers
    Alex

  • Highlighting a ROw in a tablular form based on a column in the row

    I have a tabular form that Has two types of records. If flightLogType = 1 then I want to highlight the row. If flightLogType=0 then no highlight. Does anyone know how to do this.

    Hi,
    I did example
    http://apex.oracle.com/pls/otn/f?p=40323:57
    Report select is just
    SELECT * FROM empI did copy my favorite report template to new name.
    Then I did edit Column Templates.
    I did set Column Template 1 conditionally "Use Based on PL/SQL expression".
    Column Template 1 Expression
    #DEPTNO# != 10To Column Template 2 I did copy what is in Template 1 and add style="background:red"Column Template 2
    <td #ALIGNMENT# headers="#COLUMN_HEADER#" class="t14data" style="background:red">#COLUMN_VALUE#</td>Column Template 2 Condition "Use Based on PL/SQL expression"
    Template 2 Expression
    #DEPTNO# = 10Then I did change report use new template
    This might help also
    http://download.oracle.com/docs/cd/E14373_01/appdev.32/e11838/themes.htm#sthref1772
    Br,Jari
    Edited by: jarola on May 11, 2010 11:24 PM

  • Populate a field based on a drop down or multiple choice

    Would it be possible to add a feature that allows users to populate a field based on the value of another field?
    I'm trying to setup a form where a technician selects their name from a drop down list, and then have the form populate their e-mail address based on their name. I would prefer to avoid forcing them to type in their e-mail address every single time so that they can get a copy of their form responses when they submit a form.
    Thanks!

    Hi,
    Thank you for your feedback. You can vote fo the calculations feature using this form:
    https://adobeformscentral.com/?f=XnF-KJVCovcEVQz9tZHYPQ
    Regards,
    Brian

  • Lock Cascade With Select for UPDATE

    If I had a employee table and a phone table with a parent/child relationship and a primary key constraint on the employee table-will issuing a select for update on the employee also lock the corresponding child rows on the phone table ?
    If not how can I bring this about ?

    You only need two sessions:
    First session: Issue the 'select for update'
    statements for the row(s) in both tables, don't
    rollback or commit
    Second session: try to update a row that you tried to
    lock in the first session (with NOWAIT).
    Thanks. I can try this definitely. A basic question.
    You are asking me to do a join on both the tables right ?
    Not two individual SQL statements ?
    Updating the primary key is known as a Bad Idea (tm).
    The key should never be touched because it should be
    meaningless. When you have a column that holds 'real'
    information it is no candidate for a primary key.
    Rgds,
    GuidoYes I am aware of that. I was just wondering what is the meaning behind this statement from this link ?
    http://www.akadia.com/services/ora_locks_survival_guide.html
    And the exact phrase from that link under the section Referential Integrity Locks (RI Locks)
    "RI constraints are validated by the database via a simple SELECT from the dependent (parent) table in question-very simple, very straightforward. If a row is deleted or a primary key is modified within the parent table, all associated child tables need to be scanned to make sure no orphaned records will result. "
    Thanks again.

  • Unlock SELECT FOR UPDATE

    I have to do a "SELECT FOR UPDATE" query to modify a CLOB column.
    The problem is that i want to release this lock BEFORE i commit or rollback de transaction.
    How can i do it?
    Thanks

    Also, i want to release the lock to prevent a deadlock with another transaction, but without doing a commit, so i can rollback it if any error is produced after. You must remember that releasing the lock means that you are not interested in that part of the transaction (or the entire transaction). You cannot have the option of releasing the lock and preserving the transaction so as to allow others to do whatever with that data. This will violate transaction integrity.
    Partial rollback seems to be what you need. If the driver is the problem, you could always package your logic into a procedure (prefarably in a package) and call that procedure from your driver (hoping the driver allows calling of stored procedures).

  • Unable to select SOME external users in person or group column in SharePoint O365

    Here's a head scratcher.
    We have an O365 SharePoint(G3) instance.
    Sent external users invites to join the site from the SharePoint Group that the external user will be placed.
    External users accepted invitations and now have access to the site with the correct permissions.
    Permissions assigned to SharePoint Group.
    Some external users can be selected for "Assigned to" field (person or group column type).
    Some external users canNOT be selected for "Assigned to" field (person or group column type).
    When typing external users name that canNOT be selected, the error message "No results found" appears.
    Went to Site Settings > Site Permisisons > Check Permissions and typed in external users name that canNOT be selected, the error message "No results found" appears.
    I have no idea why this would happen for some external users and not others.
    External users that can be selected and those that canNOT be selected are in the same SharePoint Group and have the same permissions.
    Could this be due to how the external user set up their account?
    Help me please. This is driving my crazy.
    Thanks in advance.
    Tamara
    The Stumped SharePointer
    Tamara Bredemus SharePoint Minion...working up to Maven

    Hi Miikka,
    can you try cleaning up the user information list via powershell and reconfigure the userprofile sync.  following url contains the powershell script for user information clean up
    http://blog.fpweb.net/how-to-clean-up-sharepoint-user-information-list-with-powershell/#.VPrbn_mUeSo
    Regards  Roy Joyson
    Please remember to mark your question as "answered"/"Vote helpful" if this solves/helps your problem.
    Roy Joyson

  • Conditional highlighting in standard report based on a column -disappearing

    Hi All,
    I implemented some conditional formatting on a standard report based on the thread below
    Highlighting a ROw in a tablular form based on a column in the row
    Everything works well, except when you pass the cursor over the report the highlighting disappears. It reappears if you refresh the page or scroll to the next page in the report.
    In my style tag in the template I'm just using
    style="background:red"
    Is it something to do with the template? I'm using builder 2 theme.
    Any ideas?
    Andrew

    Hi Andrew,
    this is coming from the report template - Before Each Row: <tr #HIGHLIGHT_ROW#>
    Just remove the #HIGHLIGHT_ROW# if you do not need it.
    Regards Garry

Maybe you are looking for

  • How to create the asset report in sccm 2007?

    hi can any one please give the query for asset report?

  • File Not Found after soket transfer

    I have code written to upload a file to the server. the file uploads fine when i dont specify the dir. It uploads to the server current dir, but when i try to upload it to directory "tmp/uniqueDir/filename" that i create in my code i get filnotfound

  • Time Machine Full Recovery From Wireless Backup

    I am reporting this as a learning experience for all. I just had a hard drive fail on my MacBook. Apple Care was golden and now I have a clean install with Leopard. Here is my situation. MacBook backed up via time machine on a wireless network. Windo

  • Can't View Photos on Web Page

    I have a real problem. I created pages on iWeb 8 for clients to view images and some of the people can't see anything other than the page itself without photos. So far 2 out of 4 people are having this problem. Please help if anyone has a clue as to

  • How to cause a button to compute a text field on the same page?

    I have a button called "Generate Hash" and I want to have it compute a text field and display it on the same page with the results of a simple sql query: select 'P'||substr(Sys_guid(),1,10) from dual; Is this a difficult thing to do?