Need help in update statement

hi,
how can i achieve the following logic
I have table ABC with column A varchar(20), B(int), C(varchar(20))
if A is null and B is valid number then C has to be updated with 'text'
if A is valid text and B is null then C has to be updated with 'number'
if A is valid text and B is valid number then C has to be updated with 'text-number'
thanks in advance

First Update
UPDATE ABC
SET C= 'text'
where A is null;since B is int data type it will always storeintegeres hence check not required.
Second Update
UPDATE ABC
set C = 'number'
where A is not null
and B IS NULLThird Update
UPDATE ABC
SET C = 'number-text'
WHERE A IS NOT NULL;Hope this answers.
You can get this in single update too
AND B IS NOT NULL

Similar Messages

  • Need help with update statement with multiple joins

    I've got the following select statement that is pulling 29 records:
    SELECT
    PPA.PROJECT_ID,
    PPA.SEGMENT1,
    peia.expenditure_item_id,
    peia.expenditure_type,
    pec.expenditure_comment
    FROM PA.PA_PROJECTS_ALL PPA,
    pa.pa_expenditure_items_all peia,
    pa.pa_expenditure_comments pec
    where PPA.segment1 < '2008' and
    PPA.project_id = 52 and -- just run for project # 20077119 for testing
    peia.expenditure_type = 'PAYROLL' and
    peia.project_id = ppa.project_id and
    PEC.EXPENDITURE_ITEM_ID = PEIA.EXPENDITURE_ITEM_ID;
    I need to update the pec.expenditure_comments to a static field for those 29 records. I assume I should start with the following, but not sure how to complete the where:
    update
    pa.pa_expenditure_comments pec
    set pec.expenditure_comment = 'REFERENCE HD#728'
    where
    First time that we've ever needed to update, so any and all help appreciated.

    Try using exists:
    update pa.pa_expenditure_comments pec
    set    pec.expenditure_comment = 'REFERENCE HD#728'
    where exists ( select null
                   from   pa.pa_projects_all ppa
                   ,      pa.pa_expenditure_items_all peia
                   ,      pa.pa_expenditure_comments pec2
                   where  ppa.segment1 < ''    -- not sure what you posted here, so for next time:
                                               -- please put your examples between the code tags.
                   and    ppa.project_id = 52  -- just run for project # 20077119 for testing
                   and    peia.expenditure_type = 'PAYROLL'
                   and    peia.project_id = ppa.project_id
                   and    pec2.expenditure_item_id = peia.expenditure_item_id
                   and    pec2.expenditure_item_id = pec.expenditure_item_id
                 );

  • Need Help ASAP  my State tax form is in a PDF file and the attachment in my email says Please wait

    Need Help ASAP  my State tax form is in a PDF file and the attachment in my email says Please wait...
    I tried downloading updates like it said to but it still will not display the document.  How do I print the PDF file ASAP

    Can you give us a LOT more info?
    What email client? What version of Reader (I can only assume you even have Reader at this point)?
    Please wait? I'm sure it says more than that, right?
    Have you tried simply saving the PDF (it IS a PDF correct?) to your desktop and opening it from there?
    Did you get this form from the IRS or did it come from somewhere else? If the IRS again, what version of Reader?
    Help us help you.

  • HT201541 I need help with updating my browser.

    I need help with updating my browser.  Its telling me that Safari is outdated.

    That is a very old version belonging to Snow Leopard. I take it you are not actually running Yosemite.
    Upgrading to Yosemite
    You can upgrade to Yosemite from Lion or directly from Snow Leopard. Yosemite can be downloaded from the Mac App Store for FREE.
    Upgrading to Yosemite
    To upgrade to Yosemite you must have Snow Leopard 10.6.8 or Lion installed. Download Yosemite from the App Store. Sign in using your Apple ID. Yosemite is free. The file is quite large, over 5 GBs, so allow some time to download. It would be preferable to use Ethernet because it is nearly four times faster than wireless.
        OS X Mavericks/Yosemite- System Requirements
          Macs that can be upgraded to OS X Yosemite
             1. iMac (Mid 2007 or newer) - Model Identifier 7,1 or later
             2. MacBook (Late 2008 Aluminum, or Early 2009 or newer) - Model Identifier 5,1 or later
             3. MacBook Pro (Mid/Late 2007 or newer) - Model Identifier 3,1 or later
             4. MacBook Air (Late 2008 or newer) - Model Identifier 2,1 or later
             5. Mac mini (Early 2009 or newer) - Model Identifier 3,1 or later
             6. Mac Pro (Early 2008 or newer) - Model Identifier 3,1 or later
             7. Xserve (Early 2009) - Model Identifier 3,1 or later
    To find the model identifier open System Profiler in the Utilities folder. It's displayed in the panel on the right.
         Are my applications compatible?
             See App Compatibility Table - RoaringApps.
    Upgrading to Lion
    If your computer does not meet the requirements to install Mavericks, it may still meet the requirements to install Lion.
    You can purchase Lion at the Online Apple Store. The cost is $19.99 (as it was before) plus tax.  It's a download. You will get an email containing a redemption code that you then use at the Mac App Store to download Lion. Save a copy of that installer to your Downloads folder because the installer deletes itself at the end of the installation.
         Lion System Requirements
           1. Mac computer with an Intel Core 2 Duo, Core i3, Core i5, Core i7,
               or Xeon processor
           2. 2GB of memory
           3. OS X v10.6.6 or later (v10.6.8 recommended)
           4. 7GB of available space
           5. Some features require an Apple ID; terms apply.

  • HT4623 I need help ASAP updating my jailbroken iPod touch 4th generation

    I have a 4th generation iPod that's jailbroke by Cydia, I need help to update it to IOS 6. From my ipod

    You can't, over-the-air update did not become available until iOS 5, you show iOS 4.1.
    And we cannot discuss jailbroken devices here per the moderators.

  • Please i need help i updated my iphone 3gs and now its not activating

    i need help i updated my iphone 3gs and now its not activating

    What happens when you try to activate the iPhone?
    If there is an error message, what is the exact wording of that message?

  • Need help for Update and cancel SalesOrder

    Hi All,
    I  written java code for create sales order based on salesquotation,now i want to update and cancel sales order ,i need help to update and cancel salesorder.
    can give any related links for update and cancel salesorder.
    Thanks and Regards,
    Srinivas

    Hi srinivas.L
    It is simple, here is some sample code. You must use getbykey to get the document. Then once you got it you can make whatever changes you need. Then update it. where i have oOrder.Update() you can have oOrder.cancel
    Dim oOrder As SAPbobsCOM.Documents
            oOrder = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)
            If oOrder.GetByKey(530) Then
                oOrder.Lines.SetCurrentLine(1)
                oOrder.Lines.WarehouseCode = "01"
                If oOrder.Update() <> 0 Then
                    MsgBox(oCompany.GetLastErrorDescription)
                End If
            Else
                MsgBox("Nothing found")
            End If
    Hope this helps

  • Need a help on Update statement

    Hi All,
    I Need a help in updating a table column. PFB my requirement.
    Table1
    ItemID OrgId       Date
    1       82     12/sep/2012   
    2       82     25/oct/2012
    3       82     17/Nov/2012
    4     82     22/Jan/2013
    5     82     26/sep/2012
    Table2
    Itemid     orgid       Date1
    1      82     23/sep/2012      
    2      82     25/Dec/2012
    3      82     17/Sep/2012
    4      82     22/Feb/2013
    5      82     26/Oct/2012
    Table3
    Itemid     orgid       Date3
    1      82     10/sep/2012      
    7      82     30/Dec/2012
    3      82     12/Sep/2012
    10      82     27/Feb/2013
    5      82     29/Oct/2012
    I Need to Update Date column of Table1 With Date3 of table3
    If
    Item and org combination is present in table3 and date column of table1 is less than Date3 of table3
    Else
    I need to Update with date2 of table2.Can we acheive this in a single update statement, can any one help me on this.
    Thanks and regards,
    Rakesh
    Edited by: Venkat Rakesh on Sep 27, 2012 11:04 PM

    You can probably also use MERGE:
    --DROP TABLE table1;
    --DROP TABLE table2;
    --DROP TABLE table3;
    ALTER SESSION SET nls_language = 'AMERICAN';
    CREATE TABLE table1
       itemid    CHAR (1),
       orgid     CHAR (2),
       thedate   DATE
    INSERT INTO table1   SELECT '1', '82', TO_DATE ('10/sep/2011', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table1   SELECT '2', '82', TO_DATE ('10/oct/2011', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table1   SELECT '3', '82', TO_DATE ('10/nov/2011', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table1   SELECT '4', '82', TO_DATE ('10/jan/2011', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table1   SELECT '5', '82', TO_DATE ('10/sep/2011', 'dd/mon/yyyy') FROM DUAL;-- won't be updated
    CREATE TABLE table2
       itemid    CHAR (1),
       orgid     CHAR (2),
       thedate   DATE
    INSERT INTO table2   SELECT '1', '82', TO_DATE ('01/sep/2012', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table2   SELECT '2', '82', TO_DATE ('01/dec/2012', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table2   SELECT '3', '82', TO_DATE ('01/sep/2012', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table2   SELECT '4', '82', TO_DATE ('01/feb/2012', 'dd/mon/yyyy') FROM DUAL;
    CREATE TABLE table3
       itemid    CHAR (1),
       orgid     CHAR (2),
       thedate   DATE
    INSERT INTO table3   SELECT '2', '82', TO_DATE ('30/dec/2009', 'dd/mon/yyyy') FROM DUAL; -- date less than table1, so picks from table2
    INSERT INTO table3   SELECT '4', '82', TO_DATE ('30/mar/2013', 'dd/mon/yyyy') FROM DUAL; -- larger than table1 , so pick this date
    -- table1 original data
    SELECT * FROM table1;
    -- merge new data
    MERGE INTO table1
         USING (SELECT NVL (t1.itemid, t2.itemid) itemid,
                       NVL (t1.orgid, t2.orgid) orgid,
                       t2.thedate prefdate ,
                       t1.thedate nextdate
                  FROM    table2 t1
                       FULL OUTER JOIN
                          table3 t2
                       ON t1.itemid = t2.itemid AND t1.orgid = t2.orgid) dat
            ON (dat.itemid = table1.itemid AND dat.orgid = table1.orgid)
    WHEN MATCHED
    THEN
       UPDATE SET table1.thedate = (case when prefdate > table1.thedate then prefdate else nextdate end) ;
    --table1 updated data
    SELECT * FROM table1;OUTPUT:
    Session altered.
    Table created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    Table created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    Table created.
    1 row created.
    1 row created.
    ITEMID ORGID THEDATE  
    1      82    10.09.2011
    2      82    10.10.2011
    3      82    10.11.2011
    4      82    10.01.2011
    5      82    10.09.2011
    5 rows selected.
    4 rows merged.
    ITEMID ORGID THEDATE  
    1      82    01.09.2012
    2      82    01.12.2012
    3      82    01.09.2012
    4      82    30.03.2013
    5      82    10.09.2011
    5 rows selected.

  • Help on update statement in Apply DML Handler

    I followed the example given in Streams document.
    The document has the code for converting DELETE on the source to INSERT on the target. I added the dml handler code INSERT and UPDATE statements also.
    In DELETE, INSERT, UPDATE dml handler code, I am setting the command type to 'INSERT' so that I can insert the data in the target table.
    It is working fine for DELETE and INSERT statements.
    When I do update on the source table,
    I see only the value for the column I updated and all other columns are showing blank. May be this is the normal behaviour. How do I see the values for entire record. Do I need to join the source table based on the key column to get the data for the columns that were not updated.
    Also, I thought I should at least see the values for key column and updated column in the target table. It only shows the value for updated column but not for key column. But, When I choosed the old values (I know we need new values, but I just did it for test purpose) in the UPDATE DML handler, it shows the values for key column and the updated column.
    When I read the data in the LCR record using get_value('old', 'EMPLOYEE_ID') and get_value('NEW', 'FIRST_NAME')
    for key column, it shows the value in both old and new. I do not understand why it is not inserting the key column value in the target table.
    Thanks for your help in advance.
    Best regards,

    I forgot to mention these things.
    We added supplmental logging using alter database add supplemental log data (primary key, unique index) columns;
    I also added the supplemental logging on the source key column (employee_id) using ALTER TABLE emp ADD SUPPLEMENTAL LOG GROUP log_group_emp_pk (employee_id) ALWAYS;
    I also set the key column on the target table using DBMS_APPLY_ADM.SET_KEY_COLUMNS.
    Thanks for your help in advance.
    Best regards,

  • Need help regarding updated rows

    Dear sir,
    need help on this query
    how many rows got updated when i execute an update statement

    If you are executing update statement from sqlplus session.
    Make sure "feedback" is turned on. It'll show numbers of rows updated just after the command;
    SQL> update tt1 set col1 = 1;
    0 rows updated.
    SQL> show feedback
    FEEDBACK ON for 1 or more rows
    SQL> set feedback off
    SQL> update tt1 set col1 = 1;
    SQL>Details about this sqlplus system setting:
    FEED[BACK] {6|n|OFF|ON}
    Display the number of records returned (when rows >= n )
    OFF (or n=0) will turn the display off
    ON will set n=1
    Regards,
    Ullhas

  • Need help in UPDATE data in SQL Query

    Hi all,
    I am trying to update data in the sql table as per below screenshot but couldn't able to do it. Can anyone help to update the data as I mention in screenshot.Appreciate you help.Thanks.
    Yellow highlighted columns are source
    Green highlighted columns are target
    Colored data should be update as per source data in sql table.Data is not static as it might have more rows to update and query should be bit dynamic.
    Maruthi...

    You have already asked this question once. You did not get any good answers, because you the information you gave was insufficient. And I'm afraid that the information is still in sufficient.
    Or more exactly, from the example you have given, the answer is: can't be done. And the reason it can't be done, is as I explained in response to you first thread: there is no information in the data to from which we can deduce that Clorox Company
    should be under "Week 1-1,K.B,F". The fact that rows are listed in a certain order in the screenshoot is of no importance, because a table is an unordered object.
    But you said in another post that you have a timestamp column. Maybe that column is usable - maybe it is not. But at least it is a key that you have more columns that the ones you show.
    The best way to get help with this type of problems is to post:
    1) CREATE TABLE statement for your table(s).
    2) INSERT statements with sample data.
    3) The desired result given the sample.
    4) A short description of the actual buisness problem you are trying to solve.
    5) Which version of SQL Server you are using.
    This makes it easy to copy and paste into a query window to develop a tested solution. Screenshots with an insufficient amount of data is not going to help you very much.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Help in Update Statement

    Hi All,
    I would like to create an update statement which produces the desired result(below) but find that the update statement I have created does not perform.
    <pre>
    CREATE TABLE RACE(
    S_ID NUMBER,
    D_PID VARCHAR2(15),
    OCCURENCE NUMBER);
    </pre>
    <pre>
    insert into RACE
    values(1,'HYD01',null);
    insert into RACE
    values(2,'HYD01',null);
    insert into RACE
    values(3,'HYD01',null);
    insert into RACE
    values(4,'HYD02',null);
    insert into RACE
    values(5,'HYD02',null);
    insert into RACE
    values(6,'HYD03',null);
    </pre>
    <pre>
    CREATE TABLE RACE_LOOKUP_CNT AS
    select d_pid,count(s_id)occurence
    from race
    GROUP BY d_pid;
    </pre>
    --Need to update the RACE table as
    S_ID DPID OCCURENCE
    1 HYD01 3
    2 HYD01 3
    3 HYD01 3
    4 HYD02 2
    5 HYD02 2
    6 HYD03 1
    Tried this subquery but kept getting multiple rows update.
    <pre>
    update RACE c
    set
    c.occurence = (
    select (a.occurence)
    from RACE_LOOKUP_CNT a
    where a.occurence in
    select occurence
    from RACE b
    AND a.d_pid =c.d_pid);
    </pre>
    Thank you all.

    -Closed-

  • Need help on case statements to validate records

    Hi Experts ,
    My table :
    seq_num
    col2
    col3
    col4
    1
    A
    12345
    P
    2
    B
    1
    123%23
    3
    C
    1
    23AB
    4
    D
    1
    20131001
    5
    E
    1
    6
    A
    13245
    Q
    7
    B
    1
    12345
    8
    C
    2
    1234*AB
    9
    D
    5
    20140112
    10
    E
    1
    00020
    my output
    seq_num
    col2
    col3
    col4
    Status
    Reason
    1
    A
    12345
    P
    Valid
    2
    B
    1
    123%23
    invalid
    Special Character for col4
    3
    C
    1
    23AB
    Valid
    4
    D
    1
    20131001
    Valid
    5
    E
    1
    invalid
    null for col4
    6
    A
    13245
    Q
    invalid
    Invalid character col4 || invalid number for col3
    7
    B
    1
    12345
    Valid
    8
    C
    2
    1234*AB
    Invalid
    Special Character col4 ||invalid col3
    9
    D
    5
    20140112
    invalid
    Future dates col4 ||invalid col3
    10
    E
    1
    00020
    Valid
    Sql :
    with t as
    ( select 1 as seq_num,'A' as col2 ,12345 as col3 ,'P' as col4 from dual
    union all
    select 2 ,'B',1,'123%23' from dual
    union all
    select 3,'C',1,'23AB' from dual
    union all
    select 4,'D',1,'21-02-2013' from dual
    union all
    select 5,'E',1,null from dual
    union all
    select 6,'A,13245,'Q' from dual
    union all
    select 7,'B',1,12345 from dual
    union all
    select 8,'C',2,'1234*AB' from dual
    union all
    select 9,'D',5,'25-01-2014' from dual
    union all
    select 10,'E',1,20 from dual
    I am applying rules on col3 and col4 for each records row-wise.
    I need case statements to populate status and reason columns after applying below rules
    Rules
    Col3 :
    For A record ,it should be 12345 always .
    For B,C,D,E , record should be always 1
    col4
    For A record , it should be either P or R
    No null values for all A, B,C,D,E records
    for B record , it dont contain special charecters
    for C RECORD ,  it dont contain special charecters
    for D record ,it should not contain future dates (dates are in yyyymmdd format and  less than  sysdates are valid )
    I have other columns as well ,as i not included here
    .It would be great if you Could  help on case statements
    Thanks and Regards,
    Sumanth

    I've adjusted Gregs nice example a bit. This should work:
    with w_base as (
          select seq_num, col2, col3, col4,
                 case when (col2 = 'A'                 AND col3 = 12345 )
                        OR (col2 in ('B','C','D','E')  AND col3 = 1)
                            then '' else '||invalid col3' end ||
                 case when (col2 = 'A'        AND col4 not IN ( 'P', 'R' ) )
                            then '||invalid col4' else '' end ||
                 case when (col2 IN ( 'B', 'C' )   AND col4 != translate(col4, 'a!@#$%^*()','a') )
                            then '||special character for col4' else '' end ||
                 case when (col2 = 'D'        AND col4 >= to_char(sysdate,'yyyymmdd') )
                            then '||future dates col4' else '' end
                   reason
          from ( select 1 as seq_num, 'A' as col2, 12345 as col3, 'P' as col4  from dual union all
                 select 2,            'B',         1,             '123%23'     from dual union all
                 select 3,            'C',         1,             '23AB'       from dual union all
                 select 4,            'D',         1,             '20130212'   from dual union all
                 select 5,            'E',         1,             null         from dual union all
                 select 6,            'A',         13245,         'Q'          from dual union all
                 select 7,            'B',         1,             '12345'      from dual union all
                 select 8,            'C',         2,             '1234*AB'    from dual union all
                 select 9,            'D',         5,             '20140125'   from dual union all
                 select 10,           'E',         1,             '20'         from dual )
    Select seq_num, col2, col3, col4,
           case when reason is null then 'Valid' else 'Invalid' end status,
           substr(reason, 3 ) reason
    from w_base
    It returns
    SEQ_NUM
    COL2
    COL3
    COL4
    STATUS
    REASON
    1
    A
    12345
    P
    Valid
    2
    B
    1
    123%23
    Invalid
    special character for col4
    3
    C
    1
    23AB
    Valid
    4
    D
    1
    20130212
    Valid
    5
    E
    1
    Valid
    6
    A
    13245
    Q
    Invalid
    invalid col3||invalid col4
    7
    B
    1
    12345
    Valid
    8
    C
    2
    1234*AB
    Invalid
    invalid col3||special character for col4
    9
    D
    5
    20140125
    Invalid
    invalid col3||future dates col4
    10
    E
    1
    20
    Valid
    edited some bugs :) now it should be fine! really

  • Need help in update

    Hi,
    In a table we having date columns but data is loaded like below.
    e.g.- 0012/04/12 :00:00:00
    however we need to do data fix for those columns to update first two digits (00) to 20 in the Table.
    e.g :- updated value : 2012/04/12:00:00:00
    Please let me know if there are any suggestions
    thanks in advance

    user586 wrote:
    Hi,
    In a table we having date columns but data is loaded like below.
    e.g.- 0012/04/12 :00:00:00
    however we need to do data fix for those columns to update first two digits (00) to 20 in the Table.
    e.g :- updated value : 2012/04/12:00:00:00
    Please let me know if there are any suggestionsuse UPDATE statement
    what datatype is the column that holds this data?
    How do I ask a question on the forums?
    SQL and PL/SQL FAQ
    Handle:     user586
    Status Level:     Newbie
    Registered:     Mar 28, 2006
    Total Posts:     222
    Total Questions:     46 (44 unresolved)
    why so MANY unanswered questions?

  • Need Help On SQL Statement

    I am using Sybase as my back end database. I need help on my SQL statement regarding datetime. The datetime is store as a 9 digit integer in the database (...I believe it is a Decimal(30,6) format, let me know if I am wrong).
    If I do this, "select * from mytable;" It works out fine (except I don't know what the date means e.g. 998919534)
    If I do this, "select * from mytable where datetime_col < '9/5/2002' ; I got an error. I even tried '9/5/02 11:00 000 am' but it didn't help.
    How do I specify a date or datetime in my query?
    Thanks in advance.

    I execute the sql statement
    select * from mytable where datetim_col < convert(datetime, '3/4/2002', 101) ;
    I got mix result. I got an error message "cannot convert 10375584 to a date.
    Yet, he statistics window of the I-sql says
    "estimated 493 rows in query (I/O estimate 87)
    PLan> mytable (seq)"
    It looks like I my the SQL statement is correct and then the system can't display it in the Data window.
    Any thought ?

Maybe you are looking for

  • OBIEE generates broken SQL

    Dear guru. Let me know what's may be wrong ? My post is closely related to bad SQL thread. Shortly speaking, I'd like to discuss multiple star problem. So, Oracle Business Intelligence 11.1.1.6.0 I have three fact table A,B,C joined to common link ta

  • Decision Step

    Hi, I have to develop a decision step to multiple users at the same time and all users should be able to see this step irrespective of anybody Accepts or Rejects this workitem. I tried creating a SubWorkflow in a loop at user table, but the SubWorkfl

  • I cannot connect to FaceTime, encountered "error processing registration, please try later" message on my Macbook Air, but I don't have this problem on my IMac. Can anyone help?

    I cannot connect to FaceTime, encountered "error processing registration, please try later" message on my Macbook Air, but I don't have this problem on my IMac. Can anyone help?

  • Redemptio code is invalid

    I just bought Acrobat PRO XI in best buy. I got a CD along with the redemption code. When I tried to get serial #, I got message that redemption code is invalid and to contact support.  I have been waiting on support on line for about 5 hours now wit

  • Please help!!! serious problem with syncing!

    Well basically when I tried to sync my ipod today it said that the ipod did not have sufficent room to import all the music I had checked. Then it came up that itunes was going to create a new playlist and it would only import music from this playlis