Help With Passing Values to a Subquery

Hello,
I am new to the SQL programming language. I have a fairly simple query that reads as follows:
SELECT Utility_Type,Instance_ID, WINS_Current_Amount/
(SELECT AVG
  (CASE WHEN (Corrected_Usage_Standardized IS NULL AND Extrapolated_Usage IS NOT NULL) 
THEN (WINS_Current_Amount/Extrapolated_Usage)
WHEN (Corrected_Usage_Standardized IS NOT NULL AND Extrapolated_Usage IS NULL) 
THEN (WINS_Current_Amount/Corrected_Usage_Standardized)
  END)
FROM All_Utility_Data_Standardized_With_Extrapolated_Values
WHERE WINS_Account_Number = '021202000'
 AND (Corrected_Usage_Standardized IS NOT NULL OR Extrapolated_Usage IS NOT NULL) 
 AND (('10-01-2013' <= WINS_Invoice_Date) AND (WINS_Invoice_Date <= '09-30-2014')))
FROM All_Utility_Data_Standardized_With_Extrapolated_Values
WHERE WINS_Account_Number = '021202000'
 AND (Corrected_Usage_Standardized IS NULL AND Extrapolated_Usage IS NULL) 
 AND (('10-01-2013' <= WINS_Invoice_Date) AND (WINS_Invoice_Date <= '09-30-2014'))
All the data I am concerned with is coming from a single table with a long-winded name (All_Utility_Data_Standardized_With_Extrapolated_Values). Essentially, the subquery takes the average of the calculated unit cost and applies that unit cost to where values
for the Current_Amount are not corrected or extrapolated. This query works great when I manually input the account number i.e. ('021202000'). But now I want to pass it 3,283 other accounts which I obtain from the following query using the same table:
SELECT DISTINCT(WINS_Account_Number)
FROM All_Utility_Data_Standardized_With_Extrapolated_Values
WHERE Corrected_Usage_Standardized IS NULL 
    AND Extrapolated_Usage IS NULL 
    AND ((WINS_Invoice_Date > '10-01-2013') AND (WINS_Invoice_Date < '09-30-2014'))
I tried to put this query in place of '021202000' but it says that Subquery returned more than 1 value which I understand why, but I'm not sure how to fix. All I want to do is one-by-one place a new account number in the bold statement in the first query
and update a table using the calculated values. Each account may have any number of results (multiple averaged results), but I need to make sure the averaging only occurs using values specific to the account entered in bold. If that makes any sense. Anyways,
any help would be much appreciated as I am just starting to learn SQL. Thanks.
Kevin

Hi Kevin, 
To fix the subquery error you just need to change "=" to "IN".  
However, the query will probably run a lot faster if you use an inner join instead, like so:
SELECT Utility_Type,Instance_ID, WINS_Current_Amount/
(SELECT AVG
  (CASE WHEN (Corrected_Usage_Standardized IS NULL AND Extrapolated_Usage IS NOT NULL) 
THEN (WINS_Current_Amount/Extrapolated_Usage)
WHEN (Corrected_Usage_Standardized IS NOT NULL AND Extrapolated_Usage IS NULL) 
THEN (WINS_Current_Amount/Corrected_Usage_Standardized)
  END)
FROM All_Utility_Data_Standardized_With_Extrapolated_Values
INNER JOIN 
SELECT DISTINCT(WINS_Account_Number)
FROM All_Utility_Data_Standardized_With_Extrapolated_Values
WHERE Corrected_Usage_Standardized IS NULL 
AND Extrapolated_Usage IS NULL 
AND ((WINS_Invoice_Date > '10-01-2013') AND (WINS_Invoice_Date < '09-30-2014'))
) Accts ON All_Utility_Data_Standardized_With_Extrapolated_Values.WINS_Account_Number = Accts.WINS_Account_Number
 AND (Corrected_Usage_Standardized IS NOT NULL OR Extrapolated_Usage IS NOT NULL) 
 AND (('10-01-2013' <= WINS_Invoice_Date) AND (WINS_Invoice_Date <= '09-30-2014')))
FROM All_Utility_Data_Standardized_With_Extrapolated_Values
INNER JOIN 
SELECT DISTINCT(WINS_Account_Number)
FROM All_Utility_Data_Standardized_With_Extrapolated_Values
WHERE Corrected_Usage_Standardized IS NULL 
AND Extrapolated_Usage IS NULL 
AND ((WINS_Invoice_Date > '10-01-2013') AND (WINS_Invoice_Date < '09-30-2014'))
) Accts ON All_Utility_Data_Standardized_With_Extrapolated_Values.WINS_Account_Number = Accts.WINS_Account_Number
 AND (Corrected_Usage_Standardized IS NULL AND Extrapolated_Usage IS NULL) 
 AND (('10-01-2013' <= WINS_Invoice_Date) AND (WINS_Invoice_Date <= '09-30-2014'))
Cheers
Lucas
LucasF

Similar Messages

  • Help with passing values to methods

      GregorianCalendar baseTime = new GregorianCalendar();
      long baseSystemTime = System.currentTimeMillis();
      // After some iterations I want to update the
      // calendar to reflect the current time.
      // I do not want to go through instantiating a new calendar
      baseTime = updateTimestamp(baseTime,baseSystemTime);
      private static GregorianCalendar updateTimestamp(GregorianCalendar GC, long lastTime){
        // This gets the difference between the last time check and now.
        // It then adds that difference to the calendar and returns the updated
        // calendar.
        int msDifference =
          new Long(System.currentTimeMillis() - lastTime).intValue();
        GC.add(GregorianCalendar.MILLISECOND,msDifference);
        lastTime = new Long(System.currentTimeMillis()).longValue();
        return GC;
      }The problem is that the lastTime variable that it passed gets updated to the current MS value. But, the original baseSystemTime never changes.
    I thought that if you pass something to a method and it gets altered in the method the original object is updated. Am I wrong?

    So objects are passed by reference but primitives are
    passed by value?Simply speaking: Yes.
    Strictly speaking: No. Every parameter is passed by value because Object obj IS a reference. So when you do call(myObject), you are passing the value of the reference of the object (the adress of the object).

  • BDC - help with passing values

    Hi,
    The BDC code works fine when the value(3) or any value is hard coded. But it is not working if I use 'RMQAM-AKTIV(p_insty)' where p_insty is the parameter value entered at selection screen. Please let me know how to pass this value.
    perform screen using: 'SAPLQPLS' '0100'.
    perform field using: 'RMQAM-AKTIV(3)' w1_aktiv,
    'BDC_OKCODE' '=WEIT',
    'RMQAM-AKTIV(3)' 'X'.
    Regards,
    bindazme

    Use this code instead.
    data lv_field(30).
    concatenate 'RMQAM-AKTIV(' p_insty ')' into lv_field.
    perform screen using: 'SAPLQPLS' '0100'.
    perform field using: lv_field w1_aktiv,
    'BDC_OKCODE' '=WEIT',
    lv_field 'X'.
    Please mark points if the solution was useful.
    Regards,
    Manoj
    Message was edited by:
            Manoj V Kumar

  • Need help with NULL values in Crosstables

    Hello everybody,
    I need some help with NULL values and crosstables. My issue is the following:
    I have a query (BW - MDX-Query) that gives me turnover measures for each month. In Crystal Reports I choose crosstable to display this whereby I put all month in columns and all turnover-measures in rows. Each month that has a value (measures are not empty) is chown in the crosstables rows. So far so good. The problem occures when there are month that actually have no values (measures are empty). In that case these months are not chown in columns. But I need CR to display these columns and show the value 0. How can I do that?

    Hi Frank,
    Cross tab shows the data based on your column and these column fields are grouped and based on the group it will show your summaries. 
    If there is no data for any of your group it will not display that group.  In this case you will have to create a standard report which should look like cross tab and to get zero values you need to write formulas .
    Example if you want to display Moth wise sales :
    if Month() = 01 Then
    sum() else 0
    Now this formula will check if your month is Jan, then it will sum up the values else it will display zero value. 
    This is possible only through standard report not with Cross Tab.
    Thanks,
    Sastry

  • How to read the 'Input help with fixed values' of domain .

    How to read the 'Input help with fixed values' of domain .
    The domain has a Value range i want to read those values .
    Are these values stored in any table ?
    Plz help me i need it ver badly...
    Thanks in Advance...

    Hi Chandra Shekhar,
    To read the 'Input help with fixed values' of domain , you can use the function module : HR_P_GET_FIXED_VALUE_TEXT.
    iIf you enter the domain name, you will find the fixed values entered in the domain.
    These values are stored in a table DD07L(DD zero 7 L). Here the values are stored based on domain name.
    See if it works for you.
    Award points if its helpful.
    Regards,
    Bhanu

  • Dropdown - issue with passing values to context

    Hi,
    After facing issue in:
    Webdynpro + alv + dynamic dropdown
    Now I've encountered another problem. Dropdown is created in alv, however once user select value from the list it shows selected value in the cell, however value in context remains unchanged.
    Here is the way I implemented dropdown:
    1) I added new field to the structure which is shown in the alv FIELD1 of WDR_CONTEXT_ATTR_VALUE_LIST type.
    2) I initialize the column, where dropdown is supposed to be:
    - first column
    l_col_name = 'COL1'.
    lr_column = lr_model->if_salv_wd_column_settings~get_column( l_col_name ).
    DATA: lr_drdn_by_idx_col1 TYPE REF TO cl_salv_wd_uie_dropdown_by_idx.
    CREATE OBJECT lr_drdn_by_idx_col1 EXPORTING selected_key_fieldname = l_col_name.
    lr_drdn_by_idx_col1->set_valueset_fieldname( value = 'FIELD1' ).
    lr_drdn_by_idx_col1->set_read_only( value = abap_false ).
    lr_drdn_by_idx_col1->set_type( if_salv_wd_c_uie_drdn_by_index=>type_key_value ).
    lr_column->set_cell_editor( lr_drdn_by_idx_col1 ).
    3) I load the data,
    Piece of code loading data into structure with dropdown:
    DATA:  ls_valueset     TYPE wdr_context_attr_value,
                lt_itab         LIKE TABLE OF ls_line.
          ls_valueset-value = 'KG'.
          ls_valueset-text = 'KG'.
          APPEND ls_valueset TO lt_itab[].
          ls_valueset-value = 'ST'.
          ls_valueset-text = 'ST'.
          APPEND ls_valueset TO lt_itab[].
    zstructure is type of the row show in the alv
    Data:
         ls_po_result TYPE zstructure.
         lt_po_result TYPE table of zstructure.
         ls_po_result-FIELD1[] = lt_itab[].
         APPEND ls_po_result TO lt_po_result[].
    Everything works so far good. The thing is that once I changed value from e.g. ST to KG, value in Attribute COL1 is still ST.
    I would appreciate your help,
    kind regards,
    Adam

    Hi Nithya,
    it could another issue with the SP, I will inform you if it's the case.
    Passing values comes up with function when I load data into alv.
    structure_name - alv columns structure
    DATA: l_name1        TYPE t001w-name1,
              ls_po_result   TYPE structure_name
              lt_po_result   TYPE table of structure_name,
    load data from DB into l_itab
      LOOP l_itab  AT ASSIGNING item.
    this method return value_set to field1
        CALL METHOD fill_single_dd
          EXPORTING
            i_id     = item-id
          IMPORTING
            rt_dd_table = ls_po_result-field1[].
        APPEND ls_po_result TO lt_po_result[].
      ENDLOOP.
    binding to node ....

  • RRI: BEX query to webadress(is SRM ITS base URL with passing value to it)

    Dear friends,
    I am doing RRI from query to webaddress,
    i have defined jump(report type: webaddress and reicver report as url) from shopping cart bex query(SRM ) to webaddres.
    here url is SRM ITS base link for monitoring shoppingcart(http://(hostname):(SRM port)/sap/bc/gui/sap/its/bbp_mon_sc?sap-client=200&sap-language=EN).
    jump is working from portal(from bex query ivew).
    but i want to pass value(shopping cart value) to above url and want to skip first screen.
    i have maintained assignment detail by assigning field name against shopping cart infoobject with type url parameter, but its not directly call reciver url with given input field.
    i tried the diffrent combination of url and field assignment as like below:
    1: web address url:http://(hostname):(SRM port)/sap/bc/gui/sap/its/bbp_mon_sc?sap-client=200&sap-language=EN
    assigned field: GS_HEADER-OBJECT_ID
    but when we call reciver url from portal bex ivew, only initial screen come with page url as below:
    http://(hostname):(SRM port)/sap/bc/gui/sap/its/bbp_mon_sc?sap-client=200&sap-language=EN?GS_HEADER-OBJECT_ID='selected number value'
    2: web address url:http://(hostname):(SRM port)/sap(cz1TSUQlM2FBTk9OJTNhc3JtZGV2X0lTRF8wMCUzYUdxdFNqdWdMS2xyTEFEelFTNFlWTnJXRjEzdy05UnhTWXl4TW03c3AtQVRU)/bc/gui/sap/its/bbp_mon_sc/~flNUQVRFPTgzMTcuMDAyLjAxLjAx====#jump_to_selected_sc
    assigned field: flNUQVRFPTgzMTcuMDAyLjAxLjAx
    but when we call reciver url from portal bex ivew, only initial screen come with page url as below:
    http://(hostname):(SRM port)/sap(cz1TSUQlM2FBTk9OJTNhc3JtZGV2X0lTRF8wMCUzYUdxdFNqdWdMS2xyTEFEelFTNFlWTnJXRjEzdy05UnhTWXl4TW03c3AtQVRU)/bc/gui/sap/its/bbp_mon_sc/~flNUQVRFPTgzMTcuMDAyLjAxLjAx====#jump_to_selected_sc?flNUQVRFPTgzMTcuMDAyLjAxLjAx='selected number value'
    I have seen the source code of that url(inital screen and after entring the value to that screen) too.
    how to call webadress(SRM ITS base shopping cart URL) with passing the one of field value of that url screen?
    Thanks and regards,
    Dushyant.

    Hi,
    i have replied wrong,
    i mean that
    when i am trying this,
    http://(hostname):(SRM port)/sap/bc/gui/sap/its/bbp_mon_sc?sap-client=200&sap-language=EN&GS_HEADER-OBJECT_ID='selected number value'
    with field assignment: shopping cart number = GS_HEADER-OBJECT_ID (for drill down on particular field, i.e. open the URL with this field value entred from sender query's field shopping cart number)
    result is coming: http://(hostname):(SRM port)/sap/bc/gui/sap/its/bbp_mon_sc?sap-client=200&sap-language=EN&GS_HEADER-OBJECT_ID='selected number value'&GS_HEADER-OBJECT_ID=10000456
    and when try this:
    http://(hostname):(SRM port)/sap/bc/gui/sap/its/bbp_mon_sc?sap-client=200&sap-language=EN
    with field assignment: shopping cart number = GS_HEADER-OBJECT_ID
    result is coming: http://(hostname):(SRM port)/sap/bc/gui/sap/its/bbp_mon_sc?sap-client=200&sap-language=EN&GS_HEADER-OBJECT_ID=10000456
    but not skiping the initial screen.
    Thanks.

  • Hello i have little problem with pass values to pop up

    I want to pass values when user click on current row then show right click context menu to pop up.
    i need help following code. Because it doesn't pass current row values , it passes all values in database. i thought filter doesn't  work .
    First i added Bind Variables named VarEnqID and Criteria named GetbyIDCriteria on my view object .
    Second i created view object classes and object interfaces and view object classes method's code :
        public void setSearch1C(String input)
            ViewCriteria vc = getViewCriteria("GetByIDCriteria");
            vc.resetCriteria();
            setVarEnqID(input);
            //setVarEnqId2(input);
            applyViewCriteria(vc);
            executeQuery();
    Third i drag setSearch1C from data control to right click context menu and add attribute named Id to bindings then choose id into value.

    How is the context menu and the pop-up wired up?
    Have you set the pop-up to lazyUncached?
    Which value from the current row do you want to pass to the method?
    Which Jdev version do you use?
    Timo

  • Help with inserting values -- ORA-00984 error

    Hello!
    This time we have a problem with inserting values and we really can't find what's wrong!
    The table was created as such
    CREATE TABLE PASSAGER
    (NO_PERSONNE INTEGER,
    NO_PASSAGER INTEGER NOT NULL,
    NO_PASSEPORT INTEGER NOT NULL,
    NATIONALITE VARCHAR2(30) NOT NULL,
    LIEU_EMISSION VARCHAR2(30) NOT NULL,
    DATE_EMISSION DATE NOT NULL,
    NO_TEL INTEGER,
    NO_CC INTEGER,
    NO_VENTE INTEGER NOT NULL,
    CONSTRAINT PK_PASSAGER PRIMARY KEY (NO_PERSONNE),
    CONSTRAINT FK_PASSAGER_PERSONNE FOREIGN KEY (NO_PERSONNE) REFERENCES PERSONNE (NO_PERSONNE),
    CONSTRAINT FK_PASSAGER_VENTE FOREIGN KEY (NO_VENTE) REFERENCES VENTE (NO_VENTE));
    We created a sequence..
    CREATE SEQUENCE NOPASS_SEQ
    START WITH 1
    INCREMENT BY 1
    NOCACHE
    NOCYCLE;
    for inserting the values, we did...
    INSERT INTO PASSAGER VALUES (500,NOPASS_SEQ.NEXTVAL, WT456789,'CANADIENNE', 'CANADA', to_date('2007/10/12','YYYY/MM/DD'),5142348756,5157981500126734,1);
    but it won't work, it's our last table and all the other worked perfectly!
    Thanks a ton!

    In your table creation, you got third column as
    NO_PASSEPORT INTEGER NOT NULL,
    where as you are passing varchar values (see bold)
    INSERT INTO PASSAGER VALUES (500,NOPASS_SEQ.NEXTVAL, WT456789,+'CANADIENNE', 'CANADA', to_date('2007/10/12','YYYY/MM/DD'),5142348756,5157981500126734,1);
    Should be like this I suppose
    INSERT INTO PASSAGER VALUES (500,NOPASS_SEQ.NEXTVAL, *456789*,'CANADIENNE', 'CANADA', to_date('2007/10/12','YYYY/MM/DD'),5142348756,5157981500126734,1);

  • Help with passing integer value in A.S.S

    I get an NSinternal script error while trying to pass this value can anyone help?
    Also I wonder if it is possible to pass the value to a matrix
    on clicked theObject
    tell button "checkbox" of window 1
    if integer value = 1 then
    set button "checkbox2" of window 1 to integer value = 1
    else
    set integer value to 0
    end if
    end tell
    end clicked
    I also tried:
    if state of button "checkbox" of window1 is 1 then
    set the state of button "checkbox2" of window1 to 1
    end if
    Message was edited by: Doug Bassett

    I've been following this thread and trying to figure out how to make this work. I was getting inconsistent results or errors with most of the code that has been posted. But I finally got it working... at least on a Leopard machine (not sure if this could have changed between Tiger and Leopard so your mileage may vary).
    What I found was that a checkbox button that's located directly in a window seems to have a state that's equal to 0 when it's unchecked and 1 when it's checked. But a checkbox cell that's contained within a matrix seems to have a state that's set to either _off state_ or _on state_. Trying to set a cell's state to 0 or 1 simply wasn't working right for me. So I get the state of the "selectall" checkbox button (which is a 0/1) and transform it to either "off state" or "on state" before setting the states of the checkbox cells in the matrix.
    Here's my code:
    on clicked theObject
    set n to name of theObject
    if n = "selectall" then
    set s to state of theObject
    log "state: " & s
    if s = 0 then
    set newState to off state
    else
    set newState to on state
    end if
    repeat with i from 1 to count of cells of matrix "directories" of window "main"
    tell cell i of matrix "directories" of window "main"
    set state to newState
    end tell
    end repeat
    return
    end if
    if n = "logStatesBtn" then
    logStates()
    return
    end if
    end clicked
    on logStates()
    log "Logging states:"
    set s to state of button "selectall" of window "main"
    log "selectall checkbox: " & s
    repeat with i from 1 to count of cells of matrix "directories" of window "main"
    tell cell i of matrix "directories" of window "main"
    set s to state
    end tell
    log "Cell " & i & ": " & s
    end repeat
    end logStates
    Note the "logStates" handler is just something I connected up to a "logStatesBtn" button in my window that lets me spit out the states of all the checkboxes into the console log. This is how I actually discovered that the cells were set to "off state" or "on state".
    Steve

  • Facing Problem with passing Values from One report to another

    Hi,
    I am Hemanth, I have developed 2 reports. Firast Report High Level Summary, Secong is detailed. First report is developed using Union(4 union) , I am having 4 columns. The report is generating the data. I have used Navigation option on Client Column to move on to Second report. In Second report with in Filter i am using Prompted option. Due to some problem, the client value from first report is not passing to the second one. The second report is getting generated for all the clients.
    Normally i have used this Navigate option in other reports and that works fine. I have even tested with Union, it works. This time it is giving some trouble.
    Please, let me know whats going wrong.
    Thanks for the help.

    sorry for the late updation.
    My First Report, Summary level is a Pivot Table.
    I tried the same report with Table option, the value is passing correctly.
    Is there a way to get rid of this situation using Pivot table.
    Thanks for your help.
    below is the original request.
    Hi,
    I am Hemanth, I have developed 2 reports. Firast Report High Level Summary, Secong is detailed. First report is developed using Union(4 union) , I am having 4 columns. The report is generating the data. I have used Navigation option on Client Column to move on to Second report. In Second report with in Filter i am using Prompted option. Due to some problem, the client value from first report is not passing to the second one. The second report is getting generated for all the clients.
    Normally i have used this Navigate option in other reports and that works fine. I have even tested with Union, it works. This time it is giving some trouble.
    Please, let me know whats going wrong.
    Thanks for the help.

  • Help with passing parameters to Aspell from C [SOLVED ENOUGH]

    I found this really cool utility called aspellstdout that will allow for rudimentary spell check in Scite:
    http://www.distasis.com/cpp/scitetip.htm#spell
    What I can't figure out (and the author didn't either) is how to pass parameters beyond language to Aspell. What I want to be able to do is pass mode switches. For instance, if I have a LaTeX document I want to be able to pass the -t switch (--mode=tex). I looked through aspell.h and couldn't see what I'm looking for.
    --EDIT--
    The output to xterm option is far easier and it makes quite a bit more sense now that I'm use to it. From my .SciTEUser.properties:
    # Rudimentary LaTeX Spell Checker
    command.name.2.$(file.patterns.tex)=Spell Check
    command.2.$(file.patterns.tex)=xterm -e aspell -t -c $(FileNameExt)
    command.subsystem.2.$(file.patterns.tex)=0
    Last edited by skottish (2008-09-08 01:58:57)

    Hi,
    I see you're using System.Data.OracleClient (which has been deprecated by MS) rather than Oracle.DataAccess.Client, but this works for me with Oracle's ODP, maybe it will help.
    Cheers,
    Greg
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
    public class dataadapterfill
        public static void Main()
            using(OracleConnection con = new OracleConnection("user id=scott;password=tiger;data source=orcl"))
                con.Open();
                using(OracleCommand cmd = new OracleCommand("select ename from emp where ename = :1", con))
                    cmd.Parameters.Add(new OracleParameter("myename", OracleDbType.Varchar2, 50)).Value = "KING";
                    OracleDataAdapter da = new OracleDataAdapter(cmd);
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    foreach (DataRow row in ds.Tables[0].Rows)
                        Console.WriteLine("ename: {0}", row["ename"]);
    }

  • Newbie needs help with passing variables or creating flash object based on parameters

    Hello Community,
    I'm an amateur developer of Ms Access databases. In one of my applications I want to visualize the options available when reaching a certain score.
    What I'd like to get from this trial period, is a flash animation of a dartboard. Depending on an array of variables that provides the fill color (or reference thereof) the layers of the flash object will be dynamicly created, altered, or switched. The dartboard itself remains "static". I'm hoping to use 9 colors.
    I can manipulate the array any way needed. I can provide XML coding to pass the array variables. I'm just too new and untrained to incorporate this in a Edge animation or Dreamweaver.
    There is no need for interaction, once the object is created (ie no user feedback).
    Can someone point me in the right direction?
    thanks in advance,
    Jay from Stockholm

    Hi,
    I see you're using System.Data.OracleClient (which has been deprecated by MS) rather than Oracle.DataAccess.Client, but this works for me with Oracle's ODP, maybe it will help.
    Cheers,
    Greg
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
    public class dataadapterfill
        public static void Main()
            using(OracleConnection con = new OracleConnection("user id=scott;password=tiger;data source=orcl"))
                con.Open();
                using(OracleCommand cmd = new OracleCommand("select ename from emp where ename = :1", con))
                    cmd.Parameters.Add(new OracleParameter("myename", OracleDbType.Varchar2, 50)).Value = "KING";
                    OracleDataAdapter da = new OracleDataAdapter(cmd);
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    foreach (DataRow row in ds.Tables[0].Rows)
                        Console.WriteLine("ename: {0}", row["ename"]);
    }

  • Help with getting values from request. Very Strange!!

    Hello,
    My very strange problem is the following.
    I have created three dynamic list boxes. When the user select
    the first list box, the second becomes populated with stuff
    from a database. The third becomes populated when the second
    is selected. Now, I have used hidden values in order for
    me to get the selected value from the first listbox. The
    following code is my first listbox:
    <SELECT NAME="resources" onChange="document.hiddenform.hiddenObject.value = this.option [this.selectedIndex].value; document.hiddenform.submit();">
    <OPTION VALUE =""> Resource</OPTION>
    <OPTION VALUE ="soil"> Soil </OPTION>
    <OPTION VALUE ="water"> Water </OPTION>
    <OPTION VALUE ="air"> Air </OPTION>
    <OPTION VALUE ="plants"> Plants </OPTION>
    <OPTION VALUE ="animals"> Animals </OPTION>
    </SELECT>
    I use the getRequest method to get the value of hiddenObject.
    At this time I am able to get the value of hiddenObject to populate
    the second list box.
    But, when the user selects an item from the second list box
    and the second form is also submitted,
    I lose the value of hiddenObject. Why is this??
    The code to populate my second listbox is the following:
    <SELECT NAME ="res_categories" onChange="document.hiddenform2.hiddenObject2.value = this.options[this.selectedIndex].value; document.hiddenform2.submit(); ">
    <OPTION VALUE ="" SELECTED> Category</OPTION>
    Here I access a result set to populate the list box.
    Please help!!

    Form parameters are request-scoped, hence the request.getParameter("hiddenObject"); call after the submission of the second form returns a null value because the hiddenObject parameter does not exist within the second request.
    A solution would be to add a hiddenObject field to your second form and alter the onChange event for res_categories to read
    document.hiddenform2.hiddenObject.value=document.1stvisibleformname.resources.option[document.1stvisibleformname.resources.selectedIndex].value;
    document.hiddenform2.hiddenObject2.value = this.options[this.selectedIndex].value;
    document.hiddenform2.submit();You will then come across a similar problem with your third drop-down if indeed you need to resubmit the form...
    A far better approach would be to create a session scoped bean, and a servlet to handle these requests. Then when the servlet is called, it would set the value of the bean property, thus making it available for this request, and all subsequent requests within the current session. This approach would eliminate the need for the clunky javascript, making your application far more stable.

  • Please help with retrieving values from object stored in a vector

    hi..
    i have a class Magazine with 2 varibles name and price like this
    class magazine
    String name;
    int price;
    i have created a vector called selectedmag which stores objects of Magazine class... now each object will contain the name and price rite...
    i want to print the values stored in vector ie i want to print the vector elements...like
    Name: Mag1
    Price: 10
    which wil be present in object1...
    and then
    Name: Mag2
    Price:15
    which wil be present in object2...
    and so on...
    plz help...
    if i give selectedmag.elementAt(position) i am not able to get the above output...plz help me.....
    thanks,
    Akshatha

    hi,
    Yes i have used a for loop to print the values... it goes like this
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    class Magazine
         String title;
         int price;
    public class sessiontrack1 extends HttpServlet
         public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
              res.setContentType("text/html");
              PrintWriter out=res.getWriter();
              HttpSession session=req.getSession(true);
    // This is my vector          
    Vector myshoppingcart=(Vector)session.getAttribute("ShoppingCart");
              if(myshoppingcart==null)
                   myshoppingcart=new Vector();
              Magazine selectedMag=new Magazine();
              selectedMag.title=req.getParameter("Title");
              selectedMag.price=Integer.parseInt(req.getParameter("Price"));
    //Putting Magazine object into the vector myshoppingcart
              myshoppingcart.addElement(selectedMag);
              session.setAttribute("ShoppingCart",myshoppingcart);
              out.println("<html><body>U have selected these magazines");
              out.println("<br>");
         //Enumeration vEnum=myshoppincart.elements();
    //here a am trying to print output the values
              for(int i=0;i<myshoppingcart.size();i++)
    out.println("Name:" + (Magazine)myshoppingcart.elementAt(i));
                   out.println("<br>");
    out.println("Price:" + (Magazine)myshoppingcart.elementAt(i));
                   out.println("<br>");
              out.println("</body></html>");
    this is a servlet program.... plz suggest me how to print the values... in the following format
    Name: Book1
    price: Rs 10
    Name:Book2
    price:Rs 15
    Akshatha

Maybe you are looking for