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.

Similar Messages

  • Making a new column out of the values from another column

    I am trying to query the transaction table and the promotion table to get the following output..
          select t.no, t.date,p.groupid,p.promocode,sum(t.salesamt)
          from trans t, promo p
          where t.id=p.tid
          group by t.no,p.groupid,p.promocode,t.date
          order by t.date
    no
    date
    groupid
    promocode
    promodesc
    sum(t.salesamt)
    m12
    01-jun-2012
    09
    p12
    Promotion1
    7890.00
    m12
    01-jun-2012
    09
    p13
    Promotion2
    345.56
    m12
    01-jun-2012
    09
    p14
    Promotion3
    2345.90
    m12
    01-jun-2012
    09
    p12
    Promotion1
    345.12
    m12
    01-jun-2012
    09
    p13
    Promotion2
    23678.00
    m12
    01-jun-2012
    09
    p14
    Promotion3
    3456.78
    I want to remove the promodesc and the sum(t.salesamt) and add Promotion1,Promotion2,Promotion3 as three new columns and their respective sum(t.salesamt) as their data value.
    I am thinking about using three separate case statements to achieve this...
    sum( case when promocode='p12' then t.salesamt end) Promotion 1
    Please let me know if there is any other optimal way to achieve this.
    Thank you!

    Hi,
    What you want is called a Pivot.  Using CASE expressions (like you described) is one common way to do pivots.  If you're using Oracle 11.1 (or higher) then you'd probably want to use the SELECT ... PIVOT feature instead.  See the SQL Language manual
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_10002.htm#sthref6809
    and the forum FAQ
    https://forums.oracle.com/message/9362005
    for details and examples.
    If you get stuck, post your best attempt, along with CREATE TABLE and INSERT statements for a little sample data, and the results you want from that data (if different from what you've already posted).
    Always say which version of Oracle you're using (for example, 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Conditionally Formatting One Column Based On The Value of Another Column

    I have the following requirement:
    I have 2 columns in a report showing Actual Sales & Budget Sales each year. I am using a bar chart to show the different values for these 2 columns.
    I need to conditionally format the column "Actual Sales" so that if it is less than the "Budget Sales" it will appear in red, and green if "Actual Sales" is greater than "Budget Sales." So in a nutshell,
    CASE WHEN "Actual Sales" < "Budget Sales" THEN
    RED
    ELSE
    GREEN
    END
    Thoughts anyone?

    CASE WHEN (COL1 - COL2) < 0 then Red else Green end
    regards
    John
    http://obiee101.blogspot.com

  • Set the css style of text in a column according to the value of another col

    I'd like to set the css style of text in a column according to the value of another column. Each field may end up with a different style of text as a result, for instance.
    Any ideas? I looked thru the forums but couldn't find anything.
    Thanks,
    Linda

    Does the class=”t7Header” make it into the rendered HTML?
    ---The text "class="tHeader" does not show but the other text is rendered using the style t7Header as defined in the stylesheet! Exactly what I wanted.
    You might want to use a div or a span instead of a p.
    ---Yes -
    What's very cool is we can create a display column that is dynamically filled with the html and style wrappers based on a lookup to see what style should be applied according to the actual data value. This is critical as our tables are all dynamic so I can't depend on using the additional APEX methods to control the display of a column (as the # of columns in the view vary from instance to instance) and I did not want the display specs to muddy up my SQL queries.
    I wonder why this is not well documented. It is so easy!
    Thanks again for your help.
    Linda

  • How can I get the value of "Warehose" column in a form

    How can I get the value of "Warehouse" column in the form below (I mean what table that contain this value):
    Production Supervisor >> Batches >> (Button) Material Details >> (Button) Line Allocations
    Well, for more clearly! My problem is I must have the Unit Cost of Items, so I've got it in the cm_cmpt_dtl (table), but if I want to, I must create a relation that require 2 filed, they're Item_ID and Whse_Code.
    There's no problem with Item_ID, but Whse_Code seem to be the Mission Impossible (hix, I hate that film!!!!)
    I wonder if It was right to post this topic here. But anyway I just post my question here, hope I could get some help.

    wow, many, many, many.... and many thanks!
    Just add a tiny modify to check out the Batch_type
    doc_id = (select batch_id from gme_batch_header where batch_no='&batch_number' and batch_type = 0)
    Because the batch_no can be duplicated as we also create Batch and Filrm Planned Order.
    Many thanks for your support!
    P/S: Sorry for my terrible English :P

  • Display an exception on one keyfigure based on the value of another key fig

    Hello all,
    How to run a exception based on some condition i.e
    i want to highlight the sales(key figure) which r less than the  average sales..
    where sales and average sales r keyfigures...
    i also created a cal key fig which has has value 1 if sale > avg sale...
    i.e How do i display an exception on one keyfigure depending on the value of another keyfigure??
    plz reply its urgent...
    thnx in advance...

    Hello Ajay, did you got an answer for your problem? I'm interested...
    Thx Masen
    Edited by: Masen-Fuad Marei on Nov 25, 2009 6:26 PM

  • Need to get sequence value in another column in oracle

    Hi ALL,
    I have sql query as below
    select header_id,order_number from oe_order_headers_all.
    and data it is displaying as
    heder_id     order_number
    111            500001
    121            500400
    I need to display  another field with some sequence value like as below
    id     heder_id     order_number
    1      111                    500001
    2      121                    500400
    so how to get sequence value in another column please help me on this.
    Thnaks

    You can just use ROWNUM Pseudocolumn
    select rownum id, header_id,order_number from oe_order_headers_all

  • Get the value from another node.

    Hi, expert
    In the component BT131I_SLS , I create a enhanced attribute in the node: BT131I_SLS/Details BTADMINI
    Then i define the GET-V method to create a search help for the attribute.
    Now , i want to pass a BP number to the search help function to filter the data.
    We need to get the BP number as below:
    When create a order, we input the product id ,
    then there will be a popup window , we can choose  a vendor in the window.
    The vendor number is the value which we want to pass to the search help.
    How can i do that ?
    Thanks.
    Oliver.

    Hi , expert
    Can i use the 'get_related_entities' to get the value I need?
    I think maybe i can use the method to get the value from another view which is not in my component.
    Now I write codes in the GET-V method, as below:
    method GET_V_ZZZFLD000011.
      DATA:
        LS_MAP    TYPE IF_BSP_WD_VALUEHELP_F4DESCR=>GTYPE_PARAM_MAPPING,
        LT_INMAP  TYPE IF_BSP_WD_VALUEHELP_F4DESCR=>GTYPE_PARAM_MAPPING_TAB,
        LT_OUTMAP TYPE IF_BSP_WD_VALUEHELP_F4DESCR=>GTYPE_PARAM_MAPPING_TAB.
      DATA: LV_PARTNER_NO TYPE CRMT_PARTNER_NUMBER.
      data: lr_current TYPE REF TO if_bol_bo_property_access,
            lr_entity  TYPE REF TO cl_crm_bol_entity,
            lr_col     TYPE REF TO if_bol_bo_col,
            value      TYPE string.
      lr_entity ?= me->collection_wrapper->get_current( ).
      lr_col = lr_entity->get_related_entities( iv_relation_name = 'Relation_Name' ).
      lr_current = lr_col->get_current( ).
    * value =
      LS_MAP-CONTEXT_ATTR = 'EXT.ZZZFLD000011'.
      LS_MAP-F4_ATTR      = 'LGORT'.
      APPEND LS_MAP TO: LT_OUTMAP.
    *  LS_MAP-CONTEXT_ATTR = 'EXT.ZZZFLD000011'.
    *  LS_MAP-F4_ATTR      = 'LANGU'.
    *  APPEND LS_MAP TO LT_INMAP.
      IF SY-SUBRC  = 0.
      ENDIF.
      CREATE OBJECT RV_VALUEHELP_DESCRIPTOR
        TYPE
          CL_BSP_WD_VALUEHELP_F4DESCR
        EXPORTING
          IV_HELP_ID                  = 'ZHELP_ZSAKCDD'
    *      IV_HELP_ID_KIND             = IF_BSP_WD_VALUEHELP_F4DESCR=>HELP_ID_KIND_COMP
          IV_HELP_ID_KIND             = IF_BSP_WD_VALUEHELP_F4DESCR=>HELP_ID_KIND_NAME
          IV_INPUT_MAPPING            = LT_INMAP
          IV_OUTPUT_MAPPING           = LT_OUTMAP
          iv_trigger_submit           = abap_true
    *      IV_F4TITLE                  = ' '"#    EC NOTEXT
    endmethod.
    But i don't know the Relation_Name which i can get the vender's information.
    Another question : i want to trigger the code 'get_related_entities' when i click the search help,
                                   How can i do that ?
    Thanks.
    Oliver.
    Edited by: oliver.yang on Aug 7, 2009 5:56 AM

  • How to get the values in separate columns

    Hello Everyone
    I am new to Bex, i have the sales data of 2008,2009,2010. now i have to display the sales order(key figure) for 2008,2009,2010 in separate columns for each customer(dimension) in a single report , can any one help me how to get this done in bex.
    Thanks
    Gupta

    Hi ,
    You can achieve this either creating New Selections or Restricted Key Figures.
    Right click on the structute>>>> New selcection>>> drag the year to right [  Right Click on it >>restrict it with 2008}>>>Drag the respected Key figure.
    So u will get the values 2008 in seperate column.
    COpy the New Selecten that u created and paste on the structure , chage the descriprion and year to 2009.
    do the same for 2010.
    Note:you can also achieve this by creating variable offsets.Check the following link
    http://help.sap.com/saphelp_bw33/helpdata/en/3f/89533e5ff4d064e10000000a114084/content.htm
    Regards,
    Ranganath

  • Formula to populate one Person or Group column depending on the value of another Person Group column

    I am looking for a way to popluate the Account information of a Person based on another column where there name in another column.  I have Two Columns   "Name" which is a Person or Group information type and User Account which
    is also a Person or Group Information type.  When an Invidividuals name is entered into the Name column, I what the User Account column to prepolulate.

    Hi,
    For your issue, you can automatically populate User Information depending on the value of another Person or Group column by connectting with User Information List or  connectting with User Profile Web Service:
    http://www.wonderlaura.com/Lists/Posts/Post.aspx?ID=172
    http://blogs.technet.com/b/anneste/archive/2011/11/02/how-to-create-an-infopath-form-to-auto-populate-data-in-sharepoint-2010.aspx
    Best Regards,
    Eric
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • How to get the value from another report Customizes Form

    Dear all,
    I create a report such as
    select * from mytable.table1
    where field1 = :bind_variable
    I create a menu to run this Customized Form and user have to select the bind_variable values. So I have another report created which also want this bind_variable as it WHERE Clause. But I don't want my user to key the same bind variable twice. They can just same the Customized Form and run for both report.
    Could anybody know how to get the bind_variable on 1st report and used by the 2nd report.
    Thank you very much.
    Best Rgds,
    SL Voon

    Hi,
    are you on BI7.0? There you can create variables type replacement path and get the value out from a different variable without any coding.
    regards
    Cornelia

  • Variable type Hierarchy, how to get the value from another similar variable

    Hi.
    We have created a variable, type hierarchy (using ORGEH hierarchy in HR based on 0ORGUNIT). Let's call this VAR1. We want to fill this with an User Exit, beacuse we want VAR1 to have the value from another variable, VAR2, which is also type hierarchy (and based on the same characteristic).
    However, when we program this user exit and use the VAR1 afterwards, it just behaves as if we have a single characteristic value and not a node value. As a result, we just get posts which do have the 'parent itself' as characteristic value, and none of the subnodes...  Any hints as to what we can do in our User exit to get the value passed over from VAR2 to VAR1 as a node value? Is there any spesific syntax to be used here that we are missing? ( The VAR1 and VAR2 are both defined as hierarchy variables, we have double checked...).

    Hi,
    are you on BI7.0? There you can create variables type replacement path and get the value out from a different variable without any coding.
    regards
    Cornelia

  • Getting the values in separate columns

    Hello Everyone
    I am new to Bex, i have the sales data of 2008,2009,2010. now my requirement is to display the sales order(key figure) for 2008,2009,2010 in separate columns for each customer(dimension) in a single report , can any one help me how to get this done in bex.
    Thanks
    Gupta

    Hi Rohit,
    To do that you should have calyear in dimennsion, if so simple you can do it else do the following.
    Edit your cube add calyear in time dimension and map it accordingly. 
    Go To Bex Designer :
    Select required free char, row and column (KF),
    Drag and drop calyear on top of kf (Extreem top to KF). 
    when you run your query it will display all the value according to relavant year. 
    Note :  Suppose you have 4kf in your colum and having three years data in the target then there will be 12 columns will be displayed in report, ie number of kf  X  number of year
    So, for better view or perfomance please do not forget to give restriction of year by giving variable to user. 
    Thanks
    BVR

  • If i select a check box i cant able to get the values in language columns in datagird??.......whats

    <?xml version="1.0"?>
    <!-- dpcontrols\ModifyDataGridData.mxml -->
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="500"
                    height="600" >
        <mx:Script>
            <![CDATA[
                import mx.collections.*;
                import mx.controls.*;
                import mx.events.*;
                import mx.utils.object_proxy;
                // Add event information to a log (displayed in the TextArea).
                public function collectionEventHandler(event:CollectionEvent):void {
                    switch(event.kind) {
                        case CollectionEventKind.ADD:
                            addLog("Item "+ event.location + " added");
                            break;
                        case CollectionEventKind.REMOVE:
                            addLog("Item "+ event.location + " removed");
                            break;
                        case CollectionEventKind.REPLACE:
                            addLog("Item "+ event.location + " Replaced");
                            break;
                        case CollectionEventKind.UPDATE:
                            addLog("Item updated");
                            break;
                // Helper function for adding information to the log.
                public function addLog(str:String):void {
        //        log.text += str + "\n";
                // Add a person to the ArrayCollection.
                public function addPerson():void {
                    var s:String;
                    var l:String;
                    if(rg1.selected)
                        s=rg1.label;
                    else
                        s=rg2.label;
                    if(ENG.selected)
                        l=ENG.label;
                    else
                        l=TAM.label;
                    if(ENG.selected && TAM.selected)
                        l=ENG.label.toString()+'&'+TAM.label.toString();
                    ac.addItem({Name:NameInput.text, Age:AgeInput.text,Sex:s ,Languagesknown:l});
                    clearInputs();
                // Remove a person from the ArrayCollection.
                public function removePerson():void {                // Make sure an item is selected.
                    if (dg.selectedIndex >= 0) {
                        ac.removeItemAt(dg.selectedIndex);
                // Update an existing person in the ArrayCollection.
                public function updatePerson():void {
                    var s:String;
                    var l:String;
                    if(rg1.selected)
                        s=rg1.label;
                    else
                        s=rg2.label;
                    if(ENG.selected)
                        l=ENG.label;
                    if(TAM.selected)
                        l=TAM.label;
                    if(ENG.selected && TAM.selected)
                        l=ENG.label.toString()+'&'+TAM.label.toString();
                    // Make sure an item is selected.
                    if(dg.selectedItem !== null) {
                        ac.setItemAt({Name:NameInput.text, Age:AgeInput.text,Sex:s,languageknown:l},dg.selectedIndex);
                // The change event listener for the DataGrid.
                // Clears the text input controls and updates them with the contents
                // of the selected item.
                public function dgChangeHandler():void {
                    var s:String;
                    var l:String;
                    if(rg1.selected)
                        s=rg1.label;
                    else
                        s=rg2.label;
                    if(ENG.selected)
                        l=ENG.label;
                    if(TAM.selected)
                        l=TAM.label;
                    if(ENG.selected && TAM.selected)
                        l=ENG.label.toString()+'&'+TAM.label.toString();
                    clearInputs();
                    NameInput.text = dg.selectedItem.Name;
                    AgeInput.text = dg.selectedItem.Age;
                    s=dg.selectedItem.Sex;
                    l=dg.selectedItem.Languageknown;
                // Clear the text from the input controls.
                public function clearInputs():void {
                    var s:String;
                    var l:String;
                    if(rg1.selected)
                        s=rg1.label;
                    else
                        s=rg2.label;
                    if(ENG.selected)
                        l=ENG.label;
                    if(TAM.selected)
                        l=TAM.label;
                    if(ENG.selected && TAM.selected)
                        l=ENG.label.toString()+'&'+TAM.label.toString();
                    NameInput.text = "";
                    AgeInput.text = "";
                    s="";
                    l="";
            ]]>
        </mx:Script>
        <!-- The ArrayCollection used by the DataGrid and ComboBox. -->
        <mx:ArrayCollection id="ac"
                            collectionChange="collectionEventHandler(event)">
        </mx:ArrayCollection>
        <mx:DataGrid width="450" id="dg" dataProvider="{ac}"
                     change="dgChangeHandler()">
            <mx:columns>
                <mx:DataGridColumn dataField="Name" headerText="Name"/>
                <mx:DataGridColumn dataField="Age" headerText="Age"/>
                <mx:DataGridColumn dataField="Sex" headerText="Sex"/>
                <mx:DataGridColumn dataField="Languageknown" headerText="Languageknown"/>
            </mx:columns>
        </mx:DataGrid>
        <!-- Form for data to add or change in the ArrayCollection. -->
        <mx:Form>
            <mx:FormItem label="Name">
                <mx:TextInput id="NameInput"/>
            </mx:FormItem>
            <mx:FormItem label="Age">
                <mx:TextInput id="AgeInput"/>
            </mx:FormItem>
            </mx:Form>
        <mx:Form width="300" height="90">
            <mx:RadioButtonGroup id="radiogroup1"/>
            <mx:FormItem width="53" label="Sex">
            </mx:FormItem>
            <mx:RadioButton id="rg1" label="Male"  groupName="radiogroup1"/>
            <mx:RadioButton id="rg2" label="Female" groupName="radiogroup1"/>
        </mx:Form>
        <mx:Form x="98" width="304" height="150">
            <mx:FormItem label="Languages known" >
            </mx:FormItem>
            <mx:CheckBox id="ENG" label="English" 
                         />
            <mx:CheckBox id="TAM" label="Tamil" />
            </mx:Form>
        <mx:HBox>
            <!-- Buttons to initiate operations on the collection. -->
            <mx:Button label="Add New" click="addPerson()"/>
            <mx:Button label="Update Selected" click="updatePerson()"/>
            <mx:Button label="Remove Selected" click="removePerson()"/>
            <!-- Clear the text input fields. -->
            <mx:Button label="Clear" click="clearInputs()"/>
        </mx:HBox>
    </mx:Application>

    Hi gayathriguru,
    You just need to correct the name for Languageknown while inserting object into array collection.
    ac.addItem({Name:NameInput.text, Age:AgeInput.text,Sex:s ,Languagesknown:l});
    You have by mistaken written it as Languagesknown instead of Languageknown. (<mx:DataGridColumn dataField="Languageknown" headerText="Languageknown"/>)
    Thanks and Regards
    Pooja Kuber | [email protected] | www.infocepts.com

  • Get Min value and another column value from the same row

    hi all - for each customer and product, I need to grab the row that has the min value for field Value1. I could've just done group by on customer and product and min on Value1, but I also need to grab Vlaue2 from the same row where the minimum value for
    Value1 lies.
    DECLARE @Temp TABLE (CustomerID INT, ProductID VARCHAR(10), Trans_Date Date, Value1 INT, Value2 INT)
    INSERT INTO @Temp VALUES (123, 'ABC', '1/1/2013', 10, 100)
    INSERT INTO @Temp VALUES (456, 'ASD', '1/1/2013', 40, 500)
    INSERT INTO @Temp VALUES (456, 'ASD', '2/1/2013', 90, 700)
    INSERT INTO @Temp VALUES (123, 'ABC', '2/1/2013', 20, 700)
    SELECT * FROM @Temp
    The output should be
    123, ABC, 10, 100
    456, ASD, 40, 500
    I know that I can just join the table to itself and get the desired output but I am dealing with a table that has millions of rows and I was hoping there is more efficient way to do this. any help would be highly appreciated...

    Here is a correction on your DDL to make it into nearly valid table.
    CREATE TABLE Sales
    (customer_id INTEGER NOT NULL,
    product_id CHAR(10) NOT NULL,
    transaction_date DATE NOT NULL,
    PRIMARY KEY (customer_id, product_id, transaction_date),
    value1 INTEGER NOT NULL,
    value2 INTEGER NOT NULL);
    Here is the current syntax for insertion:
    INSERT INTO Sales
    VALUES (123, 'abc', '2013-01-01', 10, 100),
    (456, 'asd', '2013-01-01', 40, 500),
    (456, 'asd', '2013-02-01', 90, 700),
    (123, 'abc', '2013-02-01', 20, 700);
    WITH
    X
    AS
    (SELECT customer_id, product_id, transaction_date, value1, value2,
    MIN(value1) OVER () AS value1_min
    FROM Sales)
    SELECT X.*
    FROM X
    WHERE X.value1_min = X.value1;
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

Maybe you are looking for

  • Motion Menus won't display video or pics!!!

    I have a dual 266 ghz "Macintel" with the latest OS and I'm running DVDSP 4.0.3 Quite recently, motion menus in DVDSP won't show video or still pics placed into their respective "drop zones"... and when I "simulate" the disk in the software, they don

  • W540 Express Card Chipset

    Hi there, I'm trying to figure out if I can use my RME Fireface 800 Audio Interface with the W540. It is firewire 800 so my two options are either thunderbolt > firewire adapter....or getting a firewire card for the Express 34 slot. Could anyone tell

  • Which Dual AMD FirePro option for Photoshop CC?

    I was wondering which of the Dual AMD FirePro option for the new Mac Pro is best for Photoshop CC. I mainly do retouching (so no video editing nor 3D rendering in Photoshop). Basically Adobe is adding GPU-accelerated features with every release. The

  • One sites constantly let Firefox almost crash: this page will not start en I have to close firefox. When I restart Firefox the problem start immeediately

    for example this page (http://www.klop.nl/kloppenframeset.htm?kloppen000082.htm#8267) starts the problem: Firefox doesn't resond at all. I close Firefox wih "Taakbeheer" and when I start Firefox again all the opened windows pop-up again and the probl

  • White screen/ no back light

    Hi people heres the brief history of my problem. 1. i had a new HD installed 2 years ago. 60gb (dont know if this info is important) 2. i had "the back light" problem for 16 months now. usually when i could find the sweet spot it would work and i jus