Update one column in different conditions

Is there any way by which I can merge following two update statements into a single statement without using plsql. Here the same column of one table is being updated in different conditions.
UPDATE week_table
SET present_week=NULL
WHERE week_table.pay_statusk=(
                    SELECT value
                    FROM panel
                    WHERE pname='PRESENT_WEEK')
UPDATE week_table
SET present_week='Y'
WHERE week_table.pay_status=(
                    SELECT value+1
                    FROM panel
                    WHERE pname='PRESENT_WEEK')
--waiting for a solution, thanks in advance.
null

Or like...
SQL> select * from week_table;
PRESENT_WE PAY_STATUS                                                          
X                   1                                                          
X                   2                                                          
SQL> select * from panel;
PNAME                     VALUE                                                
PRESENT_WEEK                  1                                                
SQL> UPDATE week_table
  2  set present_week = decode(pay_status,(select value
  3                                       from panel
  4                                       where pname = 'PRESENT_WEEK'),null,
  5                                      (select value+1
  6                                      from panel
  7                                      where pname = 'PRESENT_WEEK'),'Y')
  8  WHERE week_table.pay_status=(
  9                        SELECT value+1
10                        FROM panel
11                        WHERE pname='PRESENT_WEEK')
12  or
13   week_table.pay_status=(
14                       SELECT value
15                        FROM panel
16                        WHERE pname='PRESENT_WEEK');
2 rows updated.
SQL> select * from week_table;
PRESENT_WE PAY_STATUS                                                          
                    1                                                          
Y                   2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Group One column in different conditions

    My Test Table has column as PENDING its null or "D"
    DESC TEST
    COde           varchar2 (5)
    Pending      Varchar2 (1)
    I want to get a listing as follows .(Total count and not null count)
    CODE total COUNT PENDING count
    HOLD 8892 500
    ANZ 9 9
    RNEW 24880 8
    NORM 3646 33
    LB 715 0
    BT2K 779 779
    BNEW 2204 2204
    TRI 26 0
    CELL 3 0
    RT2K 580 0
    ZERO 17782 0
    Please explain how to do it in single sql statment

    We can do this, but please explain what you mean by pending count. Does pending hold only NULL and 'D's? If so, the total of NULLs and 'D's is what I consider to be total count. The one only with NULL is pending right?
    select code, sum(pending) total_count,
    sum(decode(pending, NULL, 1, 0)) pending_count
    from test
    group by test;Cheers
    Sarma.

  • One Key FIgure in more than one column with different restrictions

    Hi,
      I am using a key figure in more than one column with different restrictions, but restriction in one column is affecting the result in other column. What shall i do to make it independent from one another??

    Hi Pravender Chauhan,
        If you want in Single column different value for different Rows based on same Key Figure, you can create Structure where you can define different logic for each row but using same key figure.
    If you want to use different Key figures then you should have to Restricted Key Figure and for any calculation you can use calculated Key figure.
    Assign points if Useful.
    Regards,
    Rajdeep.

  • How to update multiple columns from different tables using cursor.

    Hi,
    i have two tables test1 and test2. i want to udpate the column(DEPT_DSCR) of both the tables TEST1 and TEST2 using select for update and current of...using cursor.
    I have a code written as follows :
    DECLARE
    v_mydept1 TEST1.DEPT_CD%TYPE;
    v_mydept2 TEST2.DEPT_CD%TYPE;
    CURSOR C1 IS SELECT TEST1.DEPT_CD,TEST2.DEPT_CD FROM TEST1,TEST2 WHERE TEST1.DEPT_CD = TEST2.DEPT_CD AND TEST1.DEPT_CD = 'AA' FOR UPDATE OF TEST1.DEPT_DSCR,TEST2.DEPT_DSCR;
    BEGIN
    OPEN C1;
         LOOP
              FETCH C1 INTO v_mydept1,v_mydept2;
              EXIT WHEN C1%NOTFOUND;
              UPDATE TEST2 SET DEPT_DSCR = 'PLSQL1' WHERE CURRENT OF C1;
              UPDATE TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1;
         END LOOP;
         COMMIT;
    END;
    The above code when run says that it runs successfully. But it does not updates the desired columns[DEPT_DSCR].
    It only works when we want to update single or multiple columns of same table...i.e. by providing these columns after "FOR UPDATE OF"
    I am not sure what is the exact problem when we want to update multiple columns of different tables.
    Can anyone help me on this ?

    oops my mistake.....typo mistake...it should have been as follows --
    UPDATE TEST1 SET DEPT_DSCR = 'PLSQL1' WHERE CURRENT OF C1;
    UPDATE TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1;
    Now here is the upated PL/SQL code where we are trying to update columns of different tables --
    DECLARE
    v_mydept1 TEST1.DEPT_CD%TYPE;
    v_mydept2 TEST2.DEPT_CD%TYPE;
    CURSOR C1 IS SELECT TEST1.DEPT_CD,TEST2.DEPT_CD FROM TEST1,TEST2 WHERE TEST1.DEPT_CD = TEST2.DEPT_CD AND TEST1.DEPT_CD = 'AA' FOR UPDATE OF TEST1.DEPT_DSCR,TEST2.DEPT_DSCR;
    BEGIN
    OPEN C1;
    LOOP
    FETCH C1 INTO v_mydept1,v_mydept2;
    EXIT WHEN C1%NOTFOUND;
    UPDATE TEST1 SET DEPT_DSCR = 'PLSQL1' WHERE CURRENT OF C1;
    UPDATE TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1;
    END LOOP;
    COMMIT;
    END;
    Please let us know why it is not updating by using using CURRENT OF

  • Update one column in Query only block

    Hi,
    I have a question regarding multi-record, multi-columns form block.
    A block has 100 columns (column1 to column100).
    We have two separate version of same form. In query only mode, update_allowed property of all the blocks in the form is False.
    But in query only form, one specifc column should be updateable.
    How can use Custom.pll to achive this functionality ?
    I tried following steps
    1. In when-new-item instance of column 54, wrote set_item_property and set_block_property
    2. Update allowed for block and specific item is True
    I know that Block property will override the property of items.
    Now all the items are updateable in query only form. But i want only one column updateable.
    Appreciate you valuable input on this.
    Thanks

    This is an eBusiness-related question, you should post it in the eBusiness-forum. From the "pure" forms point of view, set the Block as updateable and set all item except the one you want to be updateable to UPDATE_ALLOWED =PROPERTY_FALSE

  • Different columns having different condition in BI Answers

    i want to have an report as like in the format :
    Name of the sectors      In local currency          In foreign currency     
         "<= 12 months" ">12 months" "<= 12 months" ">12 months"
         0-250,000 >250,000 150,000- 350,000 >350,000
    Public Sector
    -Economic Public Corporations          
    -Public Business Sector Companies          
    i want to have the report in the above format ..
    where under the local currency contains there will be two colums of the range. i have got one column with <=12 months but how to get another column with less than >12 months with the condition >250000 and all in individual rows..
    Can any body please suggest..

    Hi.
    Navigation drills from one to another report using column propetries navigation only works in case that you are using the same column from the same table, and this column is IS PROMPTED in both reports.
    Example 1:
    Fact1 >- Dim1.COL1 (Report 1)
    Fact2 >- Dim2.COL1 (Report 2)
    Navigation from Report1 to Report2 is not working although Dim2.COL1 is promted and you are drilling from Dim1.COL1.
    Example 2:
    Fact1 >- Dim1.COL1 (Report 1)
    Fact2 >- Dim1.COL1 (Report 2)
    Navigation from Report1 to Report2 is working because both reports share the same table.column (Dim1.COL1) and it is prompted in the second report.
    You can use GO URL navigation for reports and dashboard pages for other cases.
    Regards,
    Goran
    http://108obiee.blogspot.com

  • Update one column while getting the value in another column

    Is it possible to in one single SQL statement update two columns in a table while at the same time obtaining the value of another column, on the same row, in the same table, and independently (that is, the update of the columns has nothing to do with the data that I want from another column)*?* Of course, I can do this in two operations, one being a "select" and the other one being an "update", but since I am in the same table and even on the same row, is it really necessary to make TWO database calls? That's why I want to combine the the two SQL-statements, for reasons of presumed effiency.

    jsun wrote:
    Is it possible to in one single SQL statement update two columns in a table while at the same time obtaining the value of another column, on the same row, in the same table, and independently (that is, the update of the columns has nothing to do with the data that I want from another column)*?* Of course, I can do this in two operations, one being a "select" and the other one being an "update", but since I am in the same table and even on the same row, is it really necessary to make TWO database calls? That's why I want to combine the the two SQL-statements, for reasons of presumed effiency.Two statements != two database calls.
    At least not in terms of SQL.
    JDBC requires a 'statement' but in SQL (depending on the data source) that can include multiple statements. An obvious example of this is a stored proc but there are other ways as well.

  • SQL update one column from another column

    I'm looking for a way to update a SQL column with a portion
    of info from another column in the same table.
    example of a sql command
    UPDATE table1
    SET table1.columnname1 = table1.columnname2
    FROM table
    WHERE blah blah blah
    Here's the thing... I only need a portion of the data found
    in the source column. I'm not sure how I would do this then.
    for example, the database has countries and states combined
    into one column like this 'US-DC', 'US-CA', US-FL', etc. I want to
    separate these into two columns, a country column and a state
    column.... and I dont want to go though all the results and do this
    line by line. How would I write the SQL command so that it puts
    just the country in the country column, and puts just the state in
    the state column, and it omits the dash all together.
    any ideas?

    It depends. Are you using PHP and mySQL or ASP and SQL?
    If you are using mysql and PHP you could use the following
    code to loop through all records in your datatbase.
    $sql="SELECT * FROM tablename"; //SET tablename to the name
    of your database table.
    $result=mysql_query($sql)or die(mysql_error(). " - $sql");
    for($x = 0; $row=mysql_fetch_assoc($result); $x++){
    //set up the variables from the table
    $ID=$row['ID']; //this is the primary key
    $var1=$row['contrystatecolumn']; //this is the name of the
    column which holds the country-state
    $var2=explode("-", $var1); //now we explode the string to get
    the country and the state seperated and place the results into an
    array
    $country=$var2[0]; //this is the first piece of the exploded
    string in the array
    $state=$var2[1]; //this is the second piece of the exploded
    string in the array
    //now we update the database record with the new information
    //remember to replace the tablename with your actual table
    name and the columns country and state with the acutal names of
    your columns in your table
    $sql2="UPDATE tablename SET country='$country'.
    state='$state' WHERE ID='$ID'";
    $result2=mysql_query($sql2)or die(mysql_error() . " -
    $sql2");
    This code will loop through every record in your table and do
    what you want very quickly.
    Hope this helps
    Stan Forrest
    Senior Web Developer
    ATG Internet

  • Need to update one column of all table in that particular schema

    hi all,
    i am using db10g.
    my task is to update one particular column's value of all the table in that schema.
    to acheive the above
    do i have to write update statement for each table or is there any way to do it in bulk?
    i hope my question make sense.
    Thanks..

    Hi karthick,
    I want to know something which is not related to this thread .
    How to include formatted post while replying to thread .
    I know using will be used  format  code before posting  . But how can we  do  it for posted message .
    I hope you understand my question .
    Thanks in advance .                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Splitting one column into different columns.

    Hello Experts,
    How do i split datetime column into different columns while doing a Select statement.
    Ex:
    The column "REC_CRT_TS" has data like "2014-05-08 08:23:09.0000000".The datatype of this column is "DateTime". And i want it in SELECT statement like;
    SELECT
    YEAR(DATETIME) YEAR,
    MONTH(DATETIME) MONTH,
    DATENAME(DATETIME) MONTHNAME,
    DATEPART(DATETIME) WEEKNUM,
    DAY(DATETIME) DATE,
    DATEPART(DATETIME) HOUR
    FROM TABLE_NAME;
    The output should look like this;
    --YEAR| MONTH | MONTHNAME| WEEKNUM | DATE | HOUR
    --2014| 5 | May | 25 | 08 |08
    Any suggestions please.
    Thanks!
    Rahman

    I made a very quick research and I see in this blog post
    http://www.jamesserra.com/archive/2011/08/microsoft-sql-server-parallel-data-warehouse-pdw-explained/
    that  It also uses its own query engine and not all features of SQL
    Server are supported.  So, you might not be able to use all your DBA tricks.  And you wouldn’t want to build a solution against SQL Server and then just hope to upsize it to Parallel Data Warehouse Edition.
    So, it is quite possible that this function doesn't exist in PDW version of SQL
    Server. In this case you may want to implement case based month name or do it in the client application.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Navigation from one column to different Reports

    Hi,
    I am using 10g.In Answers i have a doubt.
    I have a column with 30 values.These are the different Entities.
    So when i click on any entity it needs to go to particular Entity Report.Is it possible with any case conditions.
    And i have developed 30 Reports.
    Note: Here i am providng centralized report when user login into the Dashboards. Based on the that needs to navigate
    Thanks

    Hi,
        You can create one viewset. In one view set you can place any number of views.
    According to your question
    1. create viewset
    2. place the views in viewset
    3. place outbound plug in the first view amd place the inbound plug the  second view. connect those two views witg navigation link.
    4. place the outbound plug in secondview and place the inbound plug in thirdview. connect secondview and thirdview with navigation link
    5. create two actions through actions tab.
    6. create two buttons. Go to properties of the first button and bind the first actions. Similary second button.
    7. go to implementation of that actions.
    wdThis.wdFirePlugToDisplayView();
    this is the sample code in section view to display view.
    here we are passing the parameters from one view to another view.
      wdThis.wdFirePlugToDisplyView(wdContext.currentContextElement().getOptions(),wdContext.currentContextElement().getSecondLevel(),wdContext.currentContextElement().getThirdLevel());
    Regards,
    Saraswathi
    Pls reward points for useful info.

  • How to update a column with different values but all other row values r sam

    Hi,
    I have a table like this.
    Col1 col2 col3 col4
    10 20 30
    10 20 30
    10 20 30
    i need to update col4 with different values coming from other table like this
    Col1 col2 col3 col4
    10 20 30 xxxx
    10 20 30 yyyy
    10 20 30 zzzz
    how can i update the table. pls let me know how to use the where condition in the update stmt.
    thanks,
    jay
    Edited by: user2558790 on Nov 20, 2009 12:26 PM

    what is the logic for this kind of update...????
    Greetings,
    Sim

  • Want to update a column with  different column of same table

    I have a table TEST_CDR which is having 250 millions records also having partition by hash.
    there are two column in this table ID and CDR_ID want to update ID in CDR_ID but it take too much time like 24 hours or more.
    please suggest me a simple way.

    Hi,
    You can try this. but be careful about your backups and go through CTAS,nologging and parallel concepts...
    Please refer this link.
    http://www.dba-oracle.com/t_fast_batch_updates_ctas.htm
    http://www.dba-oracle.com/t_nologging_append.htm
    http://www.dba-oracle.com/t_efficient_update_sql_dml_tips.htm
    http://eriglen.blogspot.in/2011/08/ctas-create-table-as-select-with.html
    1.CTAS with nologging and parallel..
    SQL> create table test_cdr_1(id,cdr_id) nologging parallel as select id,id from test_cdr;
    2.rebuild indexes, triggers and constraints to test_cdr_1
    3.rename test_cdr to bkup_test_cdr;
    4.rename test_cdr_1 to test_cdr;
    Regards,
    ragunath.

  • Need  trigger when update one column then record sysdate on another collumn

    Hi
    Gurus
    I have a table called RTV_PLAN
    And it have two columns,
    FORCE_KEYIN_FLAG VARCHAR(2)
    FORCE_KEYIN_DATE DATE
    I want when FORCE_KEYIN_FLAG get a value
    Then FORCE_KEYIN_DATE record the sysdate
    Please kindly give some help
    Many thanks
    saven

    Hi
    Justin
    thank you!
    It works for me very well.
    I use this code before
    <div class="jive-message-body"><div class="jive-quote"><span class="jive-quote-header"> if updating then
    </div>
    with your help my code is below now,
    <div class="jive-message-body"><div class="jive-quote"><span class="jive-quote-header">
    create or replace TRIGGER "RTV_PLAN_TRIG"
    before insert or update on RTV_PLAN
    for each row
    declare
    SCRAP_flag rtv_plan.SCRAP_flag%TYPE;
    force_keyin_flag rtv_plan.force_keyin_flag%TYPE;
    begin
    if inserting then
    if :NEW.RTV_PLAN_KEY is null then
    :NEW.RTV_PLAN_KEY := SAVEN.RTV_PLAN_api.RTV_gen_pk;
    end if;
    :NEW.dc_receive_date := sysdate;
    end if;
    if ( :new.scrap_flag IS NOT NULL ) then
    :NEW.SCRAP_date := sysdate;
    :NEW.SCRAP_USER := nvl(v('APP_USER'),USER);
    end if;
    if ( :new.force_keyin_flag IS NOT NULL )
    then
    :NEW.FORCE_KEYIN_date := sysdate;
    :NEW.FORCE_KEYIN_USER := nvl(v('APP_USER'),USER);
    end if;
    end;
    </div>
    can you checking this whether they have other error ?
    thank you
    saven

  • Update one table based on condition from another table using date ranges

    Hello!
    I have two tables:
    DateRange (consists of ranges of dates):
    StartDate            FinishDate
            Condition
    2014-01-02
          2014-01-03           true
    2014-01-03     
     2014-01-13          
    false
    2014-01-13      
    2014-01-14           true
    Calendar (consists of three-year dates):
    CalendarDate    IsParental
    2014-01-01
    2014-01-02
    2014-01-03
    2014-01-04
    2014-01-05
    2014-01-06
    2014-01-07
    2014-01-08
    2014-01-09
    2014-01-10
    I want to update table Calendar by setting  IsParental=1
      for those dates that are contained in table DateRange between
    StartDate and FinishDate AND Condition  IS TRUE.
    The query without loop should look similar to this but it works wrong:
    UPDATE
    Calendar
    SET IsParental = 1
     WHERE
    CalendarDate   BETWEEN
    (SELECT
    StartDate 
    FROM  DateRange
    WHERE Calendar.  CalendarDate   = DateRange. StartDate
               AND   
    (SELECT StartDate 
    FROM  DateRange
    WHERE Calendar.  CalendarDate   = DateRange. FinishDate
    AND Condition
     IS TRUE
    Is it possible to do without loop? Thank you for help!
    Anastasia

    Hi
    Please post DDL+DML next time :-)
    -- This is the DDL! create the database structure
    create table DateRange(
    StartDate DATE,
    FinishDate DATE,
    Condition BIT
    GO
    create table Calendar(
    CalendarDate DATE,
    IsParental BIT
    GO
    -- This is the DML (insert some sample data)
    insert DateRange
    values
    ('2014-01-02', '2014-01-03', 1),
    ('2014-01-03', '2014-01-13', 0),
    ('2014-01-13', '2014-01-14', 1)
    GO
    insert Calendar(CalendarDate)
    values
    ('2014-01-01'),
    ('2014-01-02'),
    ('2014-01-03'),
    ('2014-01-04'),
    ('2014-01-05'),
    ('2014-01-06'),
    ('2014-01-07'),
    ('2014-01-08'),
    ('2014-01-09'),
    ('2014-01-10')
    select * from DateRange
    select * from Calendar
    GO
    -- This is the solution
    select CalendarDate
    from Calendar C
    where EXISTS (
    select C.CalendarDate
    FROM DateRange D
    where C.CalendarDate between D.StartDate and D.FinishDate and D.Condition = 1
    UPDATE Calendar
    SET IsParental = 1
    from Calendar C
    where EXISTS (
    select C.CalendarDate
    FROM DateRange D
    where C.CalendarDate between D.StartDate and D.FinishDate and D.Condition = 1
    [Personal Site] [Blog] [Facebook]

Maybe you are looking for

  • Exchange 2010 to Exchange 2013 mail flow?

    We are planning to migrate Exchange 2010 to Exchange 2013. I understand that we need to upgrade the CAS to 2013 for Internet Facing. What about mail flow. Currently, Internet mail flows to Exchange 2010 (single site). Can I keep it for sometime after

  • Java.lang.Exception: DEBUG

    Hi, Can you please tell the significance of these error message coming in the weblogic logs. java.lang.Exception: DEBUG at weblogic.transaction.internal.ServerResourceInfo.setState(ServerResourceInfo.java:281) java.lang.Exception: DEBUG at weblogic.t

  • ATG search 2007 and case in-sensitive search sorting

    Any one please tell me , how can we do the case in-sensitive sorting in ATG search 2007 ? please find below my current sort properties to search engine for the alphabetical sorting of the products/skus : docSortProp="displayName" docSortOrder="ascend

  • Check if file exists returns false. File is in system32

    I'm having a problem detecting if a file exists which was simply copied to the system32 directory.  I tried moving the file to various other directories and simply using a vi with the "Check if file or folder exists" action.  I've narrowed it down to

  • Totally stumped: IE 7loads .swf, but then stops

    This problem is only happening in IE 7. .swf loads, preloader plays, slide one is fine, then slide two, nothing shows up. We are using swf object to embed .swf in the page... The .swf is published as flash 8... Can anyone help out? Heard of this befo