Update some columns using case....

Hi ,
Is it possible to update some columns using case statement...????
For example when col1 is null then update to a value 'x' else update it to the value '*' , when col2 is null then update to a value y else update it to compute the running total up to that time....
This update statement is contained in db packaged procedure and it receives the values...as parameters....
How can i write down this update statement...?????
Many thanks,
Simon

Hi ,
Cant' it be used for two or more columns that have to be updated....????
i mean
update table set col_a = case when col_a is null then col_a else '*',
                   col_b = case when col_b is null then col_b else col_b+col_b_var
  end
  where .....The above in bold is running total.... This update is defined in a procedure and it receives numbers as parameters, so the need is to add them for every record it receives...., that's why i set above col_b+col_b_var... where col_b_var is the parameter of the procedure....
SORRY...IT IS POSSIBLE.....
Thanks , a lot
Simon
Message was edited by:
sgalaxy

Similar Messages

  • How are you using Javascript in your courses? Anyone have some good use cases?

    Anyone have some good use cases?

    Please click on the link mentioned below. It can be useful for you.
    https://helpx.adobe.com/captivate/using/common-js-interface.html
    Regards,
    Rajeev.

  • Update multiple rows using CASE WHEN

    I have the table ACCOUNT of structure as follow: 
    ACCOUNT_ID
    ACCOUNT_STATUS
    004460721
    2
    042056291
    5
    601272065
    3
    I need to update the three rows at once using one SELECT statement such that, the second column will be 5, 3, 2 respectively.
    I used the following query but seems there is something missing
    UPDATE ACCOUNT
    SET ACCOUNT_STATUS = CASE  
    WHEN ACCOUNT_STATUS = '004460721' THEN 5 
    WHEN ACCOUNT_STATUS = '042056291' THEN 3 
    WHEN ACCOUNT_STATUS = '601272065' THEN 2 
    WHERE ACCOUNT_ID IN ('004460721','042056291','601272065') 
    My question, is this way correct? if no, can I use CASE WHEN statement and how or I only have choice of using SUB-SELECT to acheive that in one statement?

    Hi,
    Hawk333 wrote:
    I have the table ACCOUNT of structure as follow:
    ACCOUNT_ID
    ACCOUNT_STATUS
    004460721
    2
    042056291
    5
    601272065
    3
    I need to update the three rows at once using one SELECT statement such that, the second column will be 5, 3, 2 respectively.
    I used the following query but seems there is something missing
    UPDATE ACCOUNT
    SET ACCOUNT_STATUS = CASE  
    WHEN ACCOUNT_STATUS = '004460721' THEN 5 
    WHEN ACCOUNT_STATUS = '042056291' THEN 3 
    WHEN ACCOUNT_STATUS = '601272065' THEN 2 
    WHERE ACCOUNT_ID IN ('004460721','042056291','601272065') 
    My question, is this way correct? if no, can I use CASE WHEN statement and how or I only have choice of using SUB-SELECT to acheive that in one statement?
    What happens when you try it?
    Did you mean "WHEN ACCOUNT_ID = ..."?
    A CASE expressions always needs an END keyword.
    Depending on your requirements (that is, why are those rows being changed, and how do you determine the new values) a CASE expression in an UPDATE statement, similar to what you posted, could be a good way to do it.  MERGE (instead of UPDATE) would also be an option, especially if you want to avoid updating rows that already happen to have the correct values.

  • How to Update some column values in some rows in an advanced table

    Hi Gurus,
    Can any body help on this issue.
    I am having a results table which is showing all the queried parties data queried in a seeded page in OCO module.
    Lets assume the table contains 10 rows with the below columns
    Party Name, Registry ID, Address Country, Match Percentage, Certification Level, Certification Reason, Internal Indicator, Status .
    Certification Level, Certification Reason and Internal Indicator are the dropdowns.
    The user want to update some of these fields values for some rows randomly.
    After doing this if he click on Save button, Only thosed changed rows need to get update using a Custom Procedure.
    But here all the rows irrespective of the change getting updated.
    So  how to capture the modified rows.
    Appreciate any inputs..
    Thanks
    Palepu
    Edited by: Palepu on 9 Aug, 2012 4:25 PM

    Not sure if you got the answer. You need to capture the row which got changed using the below and get the column value using the getAttribute method. This works for single selection row, if it is multi selection then you will have to loop through all selected rows and find the VO attribute value.
    String rowReference = pageContext.getParameter(OAWebBeanConstants.EVENT_SOURCE_ROW_REFERENCE);
    Row currentRow = am.findRowByRef(rowReference);
    String param1= (String)currentRow.getAttribute("VOAttribute");
    Let me know if there are any issues.
    Thanks
    Shree

  • How to update a column using hibernate

    how to update a particular column using hibernate..
    iam using oracle database

    I think you didn't get the point. This is a generic Java forum... not a Hibernate forum.

  • Update a column using cursor

    Hi everyone,
    still playing around with newbie stuff here. Is it possible to update a column or a row using a cursor? I understand how to fetch a data using a cursor, but not sure if it can help to update a data.
    If it can, what's the syntax?
    Regards,
    Valerie

    hi,
    why you opted to update rows by using cursor.
    why not you opt DML
    or
    just want to know
    SQL> SET LINE 32323
    SQL> /
    Rollback complete.
    SQL> SELECT *FROM EMP;
          7499 KITTU      SALESMAN        7698 20-FEB-81      15800      25050         30
          7566 JONES      MANAGER         7839 02-APR-81       3175     446.25         20
          7654 RAVIKUMAR  SALESMAN        7698 28-SEP-81       1450     1587.5         30 [email protected]
          7698 BLAKE      MANAGER         7839 01-MAY-81       3050      427.5         30
          7782 CLARK      MANAGER         7839 09-JUN-81       2650      367.5         10
          7788 SCOTT      ANALYST         7566 09-DEC-82       3200        450         20
          7839 KING       PRESIDENT            17-NOV-81       5200       8250         10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1700        225         30
          7876 ADAMS      CLERK           7788 12-JAN-83       1300        165         20
          7900 JAMES      CLERK           7698 03-DEC-81       1150       85.5         30 [email protected]
          7902 FORD       ANALYST         7566 03-DEC-81       3200        450         20
          7934 MILLER     CLERK           7782 23-JAN-82       1500        195         10
          8000 KINGBABA   PRESIDENT            17-NOV-81       5200       8250         10
          8001 TURNER RAV SALESMAN        8000 08-SEP-81       1700        450         30
    14 rows selected.
    SQL> DECLARE
      2  CURSOR CUR_EMP IS SELECT *FROM EMP;
      3  CUR_EMP1 CUR_EMP%ROWTYPE;
      4  BEGIN
      5  OPEN  CUR_EMP;
      6  LOOP
      7  FETCH CUR_EMP INTO CUR_EMP1;
      8  EXIT WHEN CUR_EMP%NOTFOUND;
      9  UPDATE EMP SET ENAME='TEST'
    10  WHERE ENAME=CUR_EMP1.ENAME;
    11  END LOOP;
    12  CLOSE CUR_EMP;
    13  END;
    14  /
    PL/SQL procedure successfully completed.
    SQL> SELECT *FROM EMP;
          7499 TEST       SALESMAN        7698 20-FEB-81      15800      25050         30
          7566 TEST       MANAGER         7839 02-APR-81       3175     446.25         20
          7654 TEST       SALESMAN        7698 28-SEP-81       1450     1587.5         30 [email protected]
          7698 TEST       MANAGER         7839 01-MAY-81       3050      427.5         30
          7782 TEST       MANAGER         7839 09-JUN-81       2650      367.5         10
          7788 TEST       ANALYST         7566 09-DEC-82       3200        450         20
          7839 TEST       PRESIDENT            17-NOV-81       5200       8250         10
          7844 TEST       SALESMAN        7698 08-SEP-81       1700        225         30
          7876 TEST       CLERK           7788 12-JAN-83       1300        165         20
          7900 TEST       CLERK           7698 03-DEC-81       1150       85.5         30 [email protected]
          7902 TEST       ANALYST         7566 03-DEC-81       3200        450         20
          7934 TEST       CLERK           7782 23-JAN-82       1500        195         10
          8000 TEST       PRESIDENT            17-NOV-81       5200       8250         10
          8001 TEST       SALESMAN        8000 08-SEP-81       1700        450         30
    14 rows selected.Edited by: user291283 on Sep 1, 2009 10:42 PM

  • How to select and duplicate the records and update some column values using cursor

    I have a table with 920 records, we need to update the end date to 6/30/2014 for 920 records and I need to create all 920 records with start date is 7/1/2014 and update the external value to
    CCC.
    Note: the table primary key is not auto increment, but I have sp to get the latest key for that.
    Existing table.  
    ID
    Source Name
    Internal value
    External value
    Start date
    End date
    1
    XXX
    AAA
    BBB
    1/1/2013
    6/30/2015
    Create new records
    ID
    Source Name
    Internal value
    External value
    Start date
    End date
    921
    XXX
    AAA
    CCC
    7/1/2013
    12/30/2015

    Hi ManuGT
    If I understand what you need then you ask for:
    1. updating all current rows (920 rows in the table now)
    2. insert new rows which are duplicates of the preiviews rows, but with value 'CCC' insteade of 'BBB'
    If so, there is not reason to use a cursor and it is highly NOT RECOMMENDED to use ant type of loop.
    You should work with SET and do it all in 2 simple queries:
    -- first we duplicate the existing rows,
    -- but we use the values 'CCC" and '20140107' for the new rows values
    INSERT test (SourceName, InternalValue, ExternalValue, StartDate, EndDate)
    select SourceName, 'CCC', ExternalValue, '20140107' , EndDate
    from test
    where
    -- You can use any filter that you need if you dont want to update all rows
    InternalValue = 'AAA' and ExternalValue = 'BBB' and StartDate = '20140101' and EndDate = '20140630'
    -- Now we update the old rows (check the filter! I get only the old rows since I filter the new rown out)
    UPDATE test
    SET EndDate = '20140107' -- I use date in format yyyymmdd, You can use other formats as well
    where
    -- You can use any filter that you need if you dont want to update all rows
    InternalValue = 'AAA' and ExternalValue = 'BBB' and StartDate = '20140101' and EndDate = '20140630'
    Unfortunately you did not post DDL+DML! Therefore we cant see your table structure and the data sample and we can only guess. I used Saeid's post as the basic DDL+DML.
    Please next time post DDL+DML
    here is the full code with the DDL+DML that i used:
    -- This is our DDL - A create table query:
    create table test
    ( id int identity(1,1) primary key,
    SourceName nvarchar(3),
    InternalValue nvarchar(3),
    ExternalValue nvarchar(3),
    StartDate date,
    EndDate date
    go
    -- This is our DML - A query that insert some sample data
    declare @i int = 1 ;
    while @i < 921
    begin
    insert test (SourceName, InternalValue, ExternalValue, StartDate, EndDate)
    values ('XXX', 'AAA', 'BBB', '1/1/2014', '6/30/2014' ) ;
    set @i += 1 ;
    end ;
    GO
    -- Here is the solution for the problem as I understood your needs:
    -- first we duplicate the existing rows,
    -- but we use the values 'CCC" and '20140107' for the new rows values
    INSERT test (SourceName, InternalValue, ExternalValue, StartDate, EndDate)
    select SourceName, 'CCC', ExternalValue, '20140107' , EndDate
    from test
    where
    -- You can use any filter that you need if you dont want to update all rows
    InternalValue = 'AAA' and ExternalValue = 'BBB' and StartDate = '20140101' and EndDate = '20140630'
    -- Now we update the old rows (check the filter! I get only the old rows since I filter the new rown out)
    UPDATE test
    SET EndDate = '20140107' -- I use date in format yyyymmdd, You can use other formats as well
    where
    -- You can use any filter that you need if you dont want to update all rows
    InternalValue = 'AAA' and ExternalValue = 'BBB' and StartDate = '20140101' and EndDate = '20140630'
    -- Here we just check how the result look like :-)
    select *
    from test ;
    -- And since we do not realy need this table in our server... Here we clean the DDL (you probaby DO NOT WANT TO EXECUTE THIS!)
    DROP table test
    GO
    I hope this was useful :-)
    [Personal Site] [Blog] [Facebook]

  • Update hidden column using Apply MRU

    I want to update username which is a hidden column with an value when I submit update using ApplyMRU. How can I do it?
    Apex 4.1, Browser IE/FireFox, Using Form Tabular with ApplyMRU.

    Can someone help on this?

  • Updating a column using deleted/inserted during update statement execution

    I need to capture the old value while update statement is executed. I can not insert into temp table (there are many samples online where you can use OUTPUT clause to insert data in same table or another temp table)
    something like 
     declare @count table
        id int,
        changed varchar (50)
    insert into @count (id,changed) values (2,'T')
    insert into @count (id,changed) values (3,'T')
    insert into @count (id,changed) values (4,'T')
    select * from @count
    UPDATE @count
    SET id=5,
        Changed = GETDATE() -- here instead of date, I want to get inserted.id and  deleted.id
    OUTPUT inserted.id,
           deleted.id
        where id = 2
      SELECT *FROM @count
    Any help on this will be very much appreciated....

    I am not sure to follow your question but you can get the old value just by doing:
    UPDATE @count
    SET id=5,
        Changed =  id
    OUTPUT inserted.id,
        deleted.id
    WHERE id = 2;
    since SQL Server uses all-at-once operations.
    Microsoft SQL Server 2012 T-SQL Fundamentals
    http://shop.oreilly.com/product/0790145321978.do
    AMB
    Some guidelines for posting questions...

  • Update a column using a connect by or other for hierachical relationships

    I have a column which represents the 'order' of which a record loaded out of a table.
    This 'order' is coming in wrong.
    I know, because of a relatoinship between two of the columns what the correct order should be.
    So for example if I do this:
    select transid, laborcode, supervisorfrom enclabor_iface
    connect by prior laborcode = supervisor
    start with supervisor = 0;
    I get all the records in the correct order... but of course I'd like to figure out how to use this in an update statement to update the transid columns, which is the order.
    Can someone tell me if this is possible, and if so, how to do so?
    I have tried a few things with no luck yet, as the attempt took over 15 minutes to run so I thought I had coded it badly.
    thanks
    Jeff

    Hi, Jeff,
    Sure, that's possible.
    The ROWNUM pseudo-column is assigned as the CONNECT BY clause (including ORDER SIBLINGS BY) is being applied, so you can use ROWNUM to capture the hierarchical order.
    I don't have a copy of your table, so I'll use scott.emp to illustrate:
    SELECT       ename, empno, mgr
    ,       ROWNUM          AS r_num
    FROM       scott.emp
    START WITH     mgr     IS NULL
    CONNECT BY     mgr     = PRIOR EMPNO
    ORDER SIBLINGS BY     ename
    ;Output:
    ENAME      EMPNO   MGR      R_NUM
    KING        7839                1
    BLAKE       7698  7839          2
    ALLEN       7499  7698          3
    JAMES       7900  7698          4
    MARTIN      7654  7698          5
    TURNER      7844  7698          6
    WARD        7521  7698          7
    CLARK       7782  7839          8
    MILLER      7934  7782          9
    JONES       7566  7839         10
    FORD        7902  7566         11
    SMITH       7369  7902         12
    SCOTT       7788  7566         13
    ADAMS       7876  7788         14The default CONNECT BY ordering guarantees that (for example) all of BLAKEs descendants will come after BLAKE and before anyone who is not a descendant of BLAKE. However, it says nothing about whether BLAKE will come before JONES, or vice-versa. If that's important, use ORDER SIBLINGS BY.
    To store those numbers in your table, do the query above in a MERGE statement.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    If you're asking about a DML statement, such as MERGE, the sample data will be the contents of the table(s) before the DML, and the results will be state of the changed table(s) when everything is finished.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.
    Edited by: Frank Kulash on Feb 7, 2012 11:46 AM

  • How to update the columns using sql queries?

    create table emp(eno number(5),ename varchar2(20),dno number(2),dname varchar2(20),loc_id number(3), location varchar2(10));
    insert into emp(eno,ename,dno,loc_id) values(1,'tom1',10,1);
    insert into emp(eno,ename,dno,loc_id) values(2,'tom2',20,2);
    insert into emp(eno,ename,dno,loc_id) values(3,'tom3',30,3);
    insert into emp(eno,ename,dno,loc_id) values(4,'tom4',40,4);
    insert into emp(eno,ename,dno,loc_id) values(5,'tom5',50,5);
    insert into emp(eno,ename,dno,loc_id) values(6,'tom6',60,6);
    insert into emp(eno,ename,dno,loc_id) values(7,'tom7',70,7);
    insert into emp(eno,ename,dno,loc_id) values(8,'tom8',80,8);
    create table dept(dno number(3),dname varchar2(10));
    insert into dept values(10,'RM');
    insert into dept values(10,'DD');
    insert into dept values(10,'TD');
    create table location(loc_id number(3),location varchar2(20));
    insert into location values(1,'palani');
    insert into location values(1,'salem');
    insert into location values(1,'kalpattu');
    insert into location values(1,'thirukoyilur');
    insert into location values(2,'thaeni');
    insert into location values(2,'villupuram');
    insert into location values(2,'yercaud');
    insert into location values(3,'thiruvanamalai');
    insert into location values(3,'trichy');
    insert into location values(7,'tanjore');
    insert into location values(4,'tirunelveli');
    insert into location values(4,'namakal');
    insert into location values(5,'bangalore');
    insert into location values(6,'chennai');
    insert into location values(6,'calcutta');
    insert into location values(7,'tirupathy');
    insert into location values(7,'bombay');
    insert into location values(7,'kumbokonam');
    My requirement is to update the department name and location of toms present in employee table without using cursors, loops.
    The column department number and loc_id are used for joins.
    I am in a situation to deliver my code on time.

    try this
    update emp tt
    set (dname,location ) = (
    select res,res1 from (select a.eno,a.ename,a.dno,b.dname,a.loc_id,c.location
    from emp a,
    dept b,
    location c
    where a.dno = b.dno
    and a.loc_id = c.loc_id
    ) t
    where tt.eno = t.eno
    model
    return updated rows
    partition by (eno)
    dimension by (row_number() over (order by eno) as rn)
    measures(cast (dname as varchar2(50))  as res,cast (location as varchar2(300)) as res1)
    rules
    upsert
    iterate(1000)
    until(presentv(res[iteration_number + 2],1,0) = 0)
    res[0] = res[0] ||','|| res[iteration_number + 1],
    res1[0] = res1[0] ||','|| res1[iteration_number + 1]))
    ;output
    1     tom1     10     ,RM,RM,RM,RM,DD,TD,DD,DD,TD,TD,TD,DD     1     ,palani,salem,kalpattu,thirukoyilur,palani,thirukoyilur,kalpattu,thirukoyilur,palani,salem,kalpattu,salem
    2     tom2     20          2     
    3     tom3     30          3     
    4     tom4     40          4     
    5     tom5     50          5     
    6     tom6     60          6     
    7     tom7     70          7     
    8     tom8     80          8     

  • Need to update multiple columns using another table

    I have 2 tables. and i need to update rows of 1 table using another table
    Table1
    Serial_no.     payment_date     Payment_amt
    101     22/11/2010     150
    101     18/03/2011      355
    102     15/04/2011      488
    103     20/05/2011      178
    102     14/06/2011      269
    101     28/06/2011      505
    Table2
    Serial_no     Charge_amt      Last_paymt_dt     Last_paymt_amt
    101     255
    102     648
    103     475
    I want to update Last_paymt_dt and Last_paymt_amt of table2 using Table1, I have written following update statement but it gives error that single row subquery return multiple row.
    Update Table2
    set (Last_paymt_dt,Last_paymt_amt) = (select max(payment_date, payment_amt) from table1
    where table1.Serial_no = table2.Serial_no group by payment_amt)
    kindly suggest how should i update.

    SQL> select * from table1
      2  /
    SERIAL_NO PAYMENT_DA PAYMENT_AMT
           101 22/11/2010         150
           101 18/03/2011         355
           102 15/04/2011         488
           103 20/05/2011         178
           102 14/06/2011         269
           101 28/06/2011         505
    6 rows selected.
    SQL> select * from table2
      2  /
    SERIAL_NO CHARGE_AMT LAST_PAYMT LAST_PAYMT_AMT
           101        255
           102        648
           103        475
    SQL> update  table2
      2     set  (last_paymt_dt,last_paymt_amt) = (
      3                                            select  max(payment_date),
      4                                                    max(payment_amt) keep(dense_rank last order by payment_date)
      5                                              from  table1
      6                                              where table1.serial_no = table2.serial_no
      7                                           )
      8  /
    3 rows updated.
    SQL> select * from table2
      2  /
    SERIAL_NO CHARGE_AMT LAST_PAYMT LAST_PAYMT_AMT
           101        255 28/06/2011            505
           102        648 14/06/2011            269
           103        475 20/05/2011            178
    SQL> SY.

  • Reg. Updation of PRPS table columns .use of  BAPI_BUS2054_CHANGE_MULTI

    Hi,
    I have used the sequence of BAPI calls as provided below.
    BAPI_PS_INITIALIZATION
    BAPI_BUS2054_CHANGE_MULTI
    BAPI_PS_PRECOMMIT
    BAPI_TRANSACTION_COMMIT
    I would like to update some columns of PRPS table for specified WBS element, uploading data from an excel sheet.
    I get the data from excel sheet to an internal table and pass to BAPI_BUS2054_CHANGE_MULTI row by row.
    It's strange ! .it updates every column for all the row of data w.r.t WBS element But  location field for first row data element get updated and rest ignored.
    can you please suggest me why it happens so?
    Thanks in advance.
    Regards,
    Sourya Prakash.

    Thanks for other responses I got .

  • SOme use cases in SAP XI

    Hi  all,
    I am trying to find reasons or some particular use cases when "business Logic"  WILL have to be handled in SAP PI/ XI .. Interfaces are quite simple and trouble-free when the logic is dumped into the SAP side (probably ABAP)...
    some use cases where in logic would eventually end up in SAP PI is what I am looking for.. .
    Also, clarify my understanding that within SAP PI business logic should be only minimal..
    Regards,
    XA

    SAP JAVA WEB AS: SAP Netweaver JAVA Application server
    Standalone JAVA AS: Some Java application server
    Java application serversThe Web modules include servlets, JavaServer Pages and Enterprise JavaBeans. Business logic resides in Enterprise JavaBeans - a modular server component providing many features, mostly improving application scalability. The Hibernate project offers an EJB-3 container implementation for the JBoss application server. Tomcat from Apache and JOnAS from ObjectWeb exemplify typical containers that can store these modules. The EAServer is from Sybase inc.
    A Java Server Page (JSP) (a servlet from Java u2014 the Java equivalent of a CGI script) executes in a Web container. JSPs provide a way to create HTML pages by embedding references to the server logic within the page. HTML coders and Java programmers can work side by side by referencing each other's code from within their own.
    The application servers mentioned above mainly serve Web applications. Some application servers target networks other than web-based ones: Session Initiation Protocol servers, for instance, target telephony networks.
    Web Server is a sub set but the Application server is a super set and hence encompasses the past server information that is been stored in database

  • Query: Predictive Use Cases for Customer Acquisition during Launch Phase

    Dear all,
    May I ask you to help me with some Predictive Use Cases (essentially SAP InfiniteInsight) for a Telco Customer who is going to launch new 4G services.
    Some important points to note are:
    1) Being a new product launch, there is no historical data about customers.
    2) Predictive use cases should help the customer acquire more customers (higher acquisition rates)
    This means that the traditional churn, next best activity, product recommendations scenarios would not be a great fit because they would essentially be coming in the grow phase.
    Additional info: The customers has other businesses in retails, mining, refinery.
    Rg,
    Ankit

    Since you do have the CC currently so you should have CS6 included as part of his membership.  The download previous version section discussed in Install and update apps - https://helpx.adobe.com/creative-cloud/help/install-apps.html provides guidance on how to install through the Creative Cloud Desktop application.
    If you don’t have high speed Internet access available on the computer you can install on then you can download the installation files from http://helpx.adobe.com/x-productkb/policy-pricing/cs6-product-downloads.html and use the steps in http://helpx.adobe.com/creative-cloud/kb/convert-cs6-licensed-under-ccm.html to license the software.
    You will need to be online to submit the periodic activation requests but it sounds like Internet access is available on the computer you are installing.
    Regards
    Rajshree

Maybe you are looking for