How to change recordset bahaviour to accept dynamic column names in the where clause

Hi
im using php-mysql and i make a recordset and i want to make the column names in the where clause to be dynamic like
"select id,name from mytable where $tablename-$myvar";
but when i do this my i break the recordset and it disappear
and when i use variables from advanced recordset it only dynamic for the value of the column not for the column name
and when i write the column name to dynamic as above by hand it truns a red exclamation mark on the server behaviour panel
so i think the only way is to change the recordset behaviour is it? if so How to make it accept dynamic column names?
thanks in advance.

As bregent has already explained to you, customizing the recordset code will result in Dreamweaver no longer recognizing the server behavior. This isn't a problem, but it does mean that you need to lay out your dynamic text with the Bindings panel before making any changes. Once you have changed the recordset code, the Bindings panel will no longer recognize the recordset fields.
Using a variable to choose a column name is quite simple, but you need to take some security measures to ensure that the value passed through the query string isn't attempting SQL injection. An effective way of doing this is to create an array of acceptable column names, and check that the value matches.
// create array of acceptable values
$valid = array('column_name1', 'column_name2', 'column_name3');
// if the query string contains an acceptable column name, use it
if (isset($_GET['colname']) && in_array($_GET['colname'], $valid)) {
  $col = $GET['colname'];
} else {
  // set a default value if the submitted one was invalid
  $col = 'column_name1'
You can then use $col directly in the SQL query.

Similar Messages

  • Dynamically stating the field name in the WHERE clause

    Hello All,
    Consider the following select statement.
    SELECT kunnr INTO TABLE gt_kunnr
          FROM kna1
          FOR ALL ENTRIES IN gt_table
          WHERE kunnr = gt_table-<b>cust_id</b>.
    Suppose there is a case where I do not know the name of the internal table field
    (say, "cust_id" in the above case) with which comparison is to be done in the WHERE clause. Only at runtime that fieldname is available. So in the WHERE clause can I mention it dynamically?
    I tried using the following.
    lv_fieldname =  'cust_id'.
    SELECT kunnr INTO TABLE gt_kunnr
          FROM kna1
          FOR ALL ENTRIES IN gt_table
          WHERE kunnr = gt_table-<b>(lv_fieldname).</b>
    But this is  giving a syntax error.
    Could anyone suggest an alternate approach?
    Regards
    Indrajit.

    Hi,
    It is fine with Enterprise version but when I am trying to run the following code in Rel 4.6C, I am getting a syntax error.
    TYPES: BEGIN OF ty_wherecond,
             data(72) TYPE c,
           END OF ty_wherecond.
    DATA: gt_itab1 TYPE STANDARD TABLE OF kna1,
          gt_itab2 TYPE STANDARD TABLE OF kna1.
    DATA:  BEGIN OF gt_kunnr OCCURS 0,
                kunnr TYPE kunnr,
           END OF gt_kunnr.
    PERFORM fill_itabs TABLES gt_itab1
                              gt_itab2.
    *&      Form  fill_itabs
          text
         -->P_T_TABLE  text
    FORM fill_itabs  TABLES   p_t_table
                              pt_table_dummy.
      DATA: lv_fieldname(30)   TYPE c VALUE 'pt_table_dummy-kunnr'.
      DATA: lt_wherecond   TYPE STANDARD TABLE OF ty_wherecond,
            lt_condtab     TYPE STANDARD TABLE OF hrcond,
            ls_condtab     TYPE hrcond.
      FIELD-SYMBOLS <fs_wherecond> TYPE ty_wherecond.
      pt_table_dummy[] = p_t_table[].
      CLEAR ls_condtab.
      REFRESH: lt_wherecond[],
               lt_condtab[].
      ls_condtab-field = 'KUNNR'.
      ls_condtab-opera = 'EQ'.
      ls_condtab-low   = lv_fieldname.
      APPEND ls_condtab TO lt_condtab.
      CALL FUNCTION 'RH_DYNAMIC_WHERE_BUILD'
        EXPORTING
          dbtable         = space " can be empty
        TABLES
          condtab         = lt_condtab
          where_clause    = lt_wherecond
        EXCEPTIONS
          empty_condtab   = 01
          no_db_field     = 02
          unknown_db      = 03
          wrong_condition = 04.
      LOOP AT lt_wherecond ASSIGNING <fs_wherecond>.
        REPLACE '''' WITH '' INTO <fs_wherecond>-data.
        REPLACE '''' WITH '' INTO <fs_wherecond>-data.
      ENDLOOP.
      SELECT kunnr INTO TABLE gt_kunnr
          FROM kna1
          FOR ALL ENTRIES IN pt_table_dummy
          WHERE (lt_wherecond).
      IF sy-subrc EQ 0.
      ENDIF.
    ENDFORM.                    "fill_itabs
    The syntax error says "The WHERE condition does not refer to the FOR ALL ENTRIES table".
    Even after using the FM 'RH_DYNAMIC_WHERE_BUILD' as suggested by you, the syntax error is coming.
    Could you please suggest how to ignore this?
    Regards
    Indrajit.

  • I want to use a dynamic schema name in the from clause but its not working.

    DECLARE
         vblQueryName VARCHAR2(20);
         vblSchemaName VARCHAR2(20);
    BEGIN
         SELECT CurrentSchemaName INTO vblSchemaName FROM HR_989_SCHEMA;
         vblQueryName:='060_525_020';
         INSERT /*+ APPEND(HP_ELIGIBILITIES,4) */ INTO HP_ELIGIBILITIES
              LVL1ID,
              LVL1Desc,
              LVL2ID,
              LVL2Desc,
              LVL3ID,
              LVL3Desc,
              LVL4ID,
              LVL4Desc
         SELECT /*+ PARALLEL(a,4) */
              LVL1ID,
              LVL1Desc,
              LVL2ID,
              LVL2Desc,
              LVL3ID,
              LVL3Desc,
              LVL4ID,
              LVL4Desc
         FROM
         bold     vblSchemaName.HP_ELIGIBILITIES a
         WHERE
              UPPER(LVL2ID) = 'XX' ;
         COMMIT;
    DBMS_OUTPUT.PUT_LINE( 'Query Executed: ' || vblqueryName);
    INSERT INTO HP_QUERYEXECLOG(QueryName) VALUES(vblQueryName);
    EXCEPTION WHEN NO_DATA_FOUND THEN NULL;
    END;
    I want to create a rules table so that the schema name in front of the table name in the from clause can be controlled by a separate table that is maintained but its not working . Help and your valuable inputs needed for this issue

    I want to use a dynamic schema name in the from clauseyou can alternatively set the current schema as e.g. in:
    declare
       vblqueryname    varchar2 (20);
       vblschemaname   varchar2 (20);
    begin
       select currentschemaname into vblschemaname from hr_989_schema;
       vblqueryname := '060_525_020';
       execute immediate 'alter session set current_schema=' || vblschemaname;
       insert /*+ APPEND(HP_ELIGIBILITIES,4) */
             into hp_eligibilities (lvl1id,
                                    lvl1desc,
                                    lvl2id,
                                    lvl2desc,
                                    lvl3id,
                                    lvl3desc,
                                    lvl4id,
                                    lvl4desc
          select /*+ PARALLEL(a,4) */
                lvl1id,
                 lvl1desc,
                 lvl2id,
                 lvl2desc,
                 lvl3id,
                 lvl3desc,
                 lvl4id,
                 lvl4desc
            from hp_eligibilities a
           where upper (lvl2id) = 'XX';
       commit;
       dbms_output.put_line ('Query Executed: ' || vblqueryname);
       insert into hp_queryexeclog (queryname)
       values (vblqueryname);
    exception
       when no_data_found
       then
          null;
    end;

  • How can I dynamically specify a Column Name in a Where Clause of a DB

    I have a page that query the Database based on the column Name and values entered by the user. on this page I have a drop down list of all the Column names and a text field. The user can choose from any of the dropdown list option to set the column Name and also enter a value.How can I dynamically pass the option choosed by the user from the drop down list to the dataProvider in seesionBean1 as a column Name???Help

    Hi,
    This is a working example of a search form.
    In the JSP page we have several texts box, a table bound to a DataProvider with the rowSet in the SessionBean and a search button.
    JSP source:
                    <ui:body binding="#{PackageAirtime.body1}" id="body1">
                        <ui:form binding="#{PackageAirtime.form1}" id="form1">
                            <table border="0">
                                <tr>
                                    <td>
                                        <table border="0" width="100%">
                                            <tr>
                                                <td>
                                                    <ui:label binding="#{PackageAirtime.pageTitle}" id="pageTitle" text="Package Airtime"/>
                                                    <br/>
                                                    <br/>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <table border="0" cellpadding="2" cellspacing="2">
                                                        <tr>
                                                            <td>Package ID:</td>
                                                            <td>
                                                                <ui:textField binding="#{PackageAirtime.textPackageID}"
                                                                    id="textPackageID"/>
                                                                <ui:button
                                                                    binding="#{PackageAirtime.buttonPackageID}" id="buttonPackageID"
                                                                    onClick="handlePackageIDPopup(); return false;" text="..." toolTip="Open package locator"/>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>Airtime Code:</td>
                                                            <td>
                                                                <ui:textField binding="#{PackageAirtime.textAirtimeCode}"
                                                                    id="textAirtimeCode"/>
                                                                <ui:button
                                                                    action="#{PackageAirtime.buttonAirtimeCode_action}"
                                                                    binding="#{PackageAirtime.buttonAirtimeCode}" id="buttonAirtimeCode"
                                                                    onClick="handleAirtimeCodePopup(); return false;" text="..." toolTip="Open airtime code locator"/>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td></td>
                                                            <td>
                                                                <ui:button action="#{PackageAirtime.searchButton_action}" binding="#{PackageAirtime.searchButton}"
                                                                    id="searchButton" text="Search" toolTip="Search records"/>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                    <br/>
                                                    <ui:staticText binding="#{PackageAirtime.staticTextSearchResults}" id="staticTextSearchResults"/>
                                                    <br/>
                                                    <ui:table binding="#{PackageAirtime.searchResults}" id="searchResults" paginationControls="true">
                                                        <script>
    /* ----- Functions for Table Preferences Panel ----- */
    * Toggle the table preferences panel open or closed
    function togglePreferencesPanel() {
      var table = document.getElementById("form1:table1");
      table.toggleTblePreferencesPanel();
    /* ----- Functions for Filter Panel ----- */
    * Return true if the filter menu has actually changed,
    * so the corresponding event should be allowed to continue.
    function filterMenuChanged() {
      var table = document.getElementById("form1:table1");
      return table.filterMenuChanged();
    * Toggle the custom filter panel (if any) open or closed.
    function toggleFilterPanel() {
      var table = document.getElementById("form1:table1");
      return table.toggleTableFilterPanel();
    /* ----- Functions for Table Actions ----- */
    * Initialize all rows of the table when the state
    * of selected rows changes.
    function initAllRows() {
      var table = document.getElementById("form1:table1");
      table.initAllRows();
    * Set the selected state for the given row groups
    * displayed in the table.  This functionality requires
    * the 'selectId' of the tableColumn to be set.
    * @param rowGroupId HTML element id of the tableRowGroup component
    * @param selected Flag indicating whether components should be selected
    function selectGroupRows(rowGroupId, selected) {
      var table = document.getElementById("form1:table1");
      table.selectGroupRows(rowGroupId, selected);
    * Disable all table actions if no rows have been selected.
    function disableActions() {
      // Determine whether any rows are currently selected
      var table = document.getElementById("form1:table1");
      var disabled = (table.getAllSelectedRowsCount()>0)?false : true;
      // Set disabled state for top actions
      document.getElementById("form1:table1:tableActionsTop:deleteTop").setDisabled(disabled);
      // Set disabled state for bottom actions
      document.getElementById("form1:table1:tableActionsBottom:deleteBottom").setDisabled(disabled);
    }</script>
                                                        <f:facet name="title">
                                                            <ui:staticText binding="#{PackageAirtime.table1Title}" id="table1Title" text="Package Airtime search results"/>
                                                        </f:facet>
                                                        <ui:tableRowGroup binding="#{PackageAirtime.tableRowGroup1}"
                                                            emptyDataMsg="No records matching the search criteria" id="tableRowGroup1"
                                                            sourceData="#{PackageAirtime.s23_package_airtimeDataProvider}" sourceVar="currentRow">
                                                            <ui:tableColumn binding="#{PackageAirtime.tableColumn1}" headerText="Package ID" id="tableColumn1" sort="S23_PACKAGE">
                                                                <ui:staticText binding="#{PackageAirtime.staticText1}" id="staticText1" text="#{currentRow.value['S23_PACKAGE']}"/>
                                                            </ui:tableColumn>
                                                            <ui:tableColumn binding="#{PackageAirtime.tableColumn2}" headerText="Airtime Code" id="tableColumn2" sort="S23_AT_CODE">
                                                                <ui:staticText binding="#{PackageAirtime.staticText2}" id="staticText2" text="#{currentRow.value['S23_AT_CODE']}"/>
                                                            </ui:tableColumn>
                                                            <ui:tableColumn binding="#{PackageAirtime.tableColumn7}" headerText="Prepaid Value" id="tableColumn7">
                                                                <ui:staticText binding="#{PackageAirtime.staticText6}" id="staticText6" text="#{currentRow.value['SUBR_AT_PREPAID_PERIOD_VAL']}"/>
                                                            </ui:tableColumn>
                                                            <ui:tableColumn binding="#{PackageAirtime.tableColumn8}" headerText="Prepaid Type" id="tableColumn8">
                                                                <ui:staticText binding="#{PackageAirtime.staticText7}" id="staticText7" text="#{currentRow.value['SUBR_AT_PREPAID_TYPE']}"/>
                                                            </ui:tableColumn>
                                                            <ui:tableColumn binding="#{PackageAirtime.tableColumn4}" headerText="Start" id="tableColumn4" sort="PRSM_PK_START">
                                                                <ui:staticText binding="#{PackageAirtime.staticText3}" id="staticText3" text="#{currentRow.value['PRSM_PK_START']}"/>
                                                            </ui:tableColumn>
                                                            <ui:tableColumn binding="#{PackageAirtime.tableColumn5}" headerText="End" id="tableColumn5">
                                                                <ui:staticText binding="#{PackageAirtime.staticText4}" id="staticText4" text="#{currentRow.value['PRSM_PK_END']}"/>
                                                            </ui:tableColumn>
                                                            <ui:tableColumn binding="#{PackageAirtime.tableColumn6}" headerText="Units" id="tableColumn6">
                                                                <ui:staticText binding="#{PackageAirtime.staticText5}" id="staticText5" text="#{currentRow.value['PRSM_PK_UNITS']}"/>
                                                            </ui:tableColumn>
                                                            <ui:tableColumn binding="#{PackageAirtime.tableColumn9}" headerText="Carry-over limit" id="tableColumn9" valign="Top">
                                                                <ui:staticText binding="#{PackageAirtime.staticText8}" id="staticText8" text="#{currentRow.value['ROM_PLAN_CARRY_LMT']}"/>
                                                            </ui:tableColumn>
                                                            <ui:tableColumn binding="#{PackageAirtime.tableColumn3}" headerText="Details" id="tableColumn3" width="100">
                                                                <ui:hyperlink action="#{PackageAirtime.viewpackageAT_action}" binding="#{PackageAirtime.hyperlink1}"
                                                                    id="hyperlink1" text="View"/>
                                                            </ui:tableColumn>
                                                        </ui:tableRowGroup>
                                                    </ui:table>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </ui:form>
                    </ui:body>
    ...JAVA source:
        public void prerender() {
            search_action();
        public String search_action() {
            try {
                String command = "SELECT s23_package, s23_at_code, prsm_pk_start, prsm_pk_end,  prsm_pk_units, subr_at_prepaid_period_val,  subr_at_prepaid_type, subr_disc_type, subr_disc_rate,  subr_disc_value, subr_disc_perm,  subr_at_prepaid_bill_per_val, subr_at_prepaid_recurring,  s23_package_fwd, s23_at_code_fwd, prsm_pk_start_fwd,  subr_ppa_infinite, subr_ppa_carry_over, rom_plan_carry_lmt  FROM s23_package_airtime, ROM_23_PPLAN_COMP  where rom_23_pack_plan = s23_package";
                String where = "";
                String packageID = (String)textPackageID.getText();
                if (packageID == null) {
                    packageID = "";
                packageID = packageID.replace("'", "''");
                if (packageID != "") {
                    if (where != "") {
                        where += " AND ";
                    where += "upper(S23_PACKAGE) LIKE upper('" + packageID + "%')";
                String airtimeCode = (String)textAirtimeCode.getText();
                if (airtimeCode == null) {
                    airtimeCode = "";
                airtimeCode = airtimeCode.replace("'", "''");
                if (airtimeCode != "") {
                    if (where != "") {
                        where += " AND ";
                    where += " upper(S23_AT_CODE) LIKE upper('" + airtimeCode + "%')";
                if (where != "") {
                    command += " AND " + where;
                this.getSessionBean1().getS23_package_airtimeRowSet().setCommand(command);
                this.staticTextSearchResults.setText(tdi.business.Utils.getRowCountMessage(s23_package_airtimeDataProvider.getRowCount()));
            catch (Exception e) {
                log("Error during search for packages airtime", e);
            return null;
        public String searchButton_action() {
            search_action();
            this.tableRowGroup1.setFirst(0);
            return "";
        }I put the search_action() call in the prerender() to have data in my table when the page is open. For a large resultset the best aproach is to let the user select some search criteria and then call the search_action() using a button (searchButton_action() ).
    I've added a hyperlink column to my table, it is used to display the current record details in a new page.
    I have defined in my SessionBean a getRowkey/setRowkey methods.
    When the user click on a "View" hiperlink the following code is executed:
        public String viewpackageAT_action() {
            RowKey row = tableRowGroup1.getRowKey();
            this.getSessionBean1().setPackageAirtimeRowKey(row);
            return "packageairtime_details";
        }I will step over the "Page Navigation".
    In the Detail Page I have the following code:
        public void init() {
           this.s23_package_airtimeDataProvider.setCursorRow(this.getSessionBean1().getPackageAirtimeRowKey());
    }Now I have the detail page opened and also the DataProvider opened at the saved RowKey value.
    Finally, in the SessionBean:
         * Holds value of property packageAirtimeRowKey.
        private RowKey packageAirtimeRowKey;
         * Getter for property packageAirtimeRowKey.
         * @return Value of property packageAirtimeRowKey.
        public RowKey getPackageAirtimeRowKey() {
            return this.packageAirtimeRowKey;
         * Setter for property packageAirtimeRowKey.
         * @param packageAirtimeRowKey New value of property packageAirtimeRowKey.
        public void setPackageAirtimeRowKey(RowKey packageAirtimeRowKey) {
            this.packageAirtimeRowKey = packageAirtimeRowKey;
        }Note: You should enable page navigation in the result(s) table.
    That's about it :)
    Hope this helps,
    Catalin Florean.

  • JSP, DataWebBean: How to dynamically set the where clause of query and display record

    Hi,
    I am reposting this question as per suggestions made by Mr. Dwight.
    I have used ViewCurrentRecord web bean to display records from EMP table. I have to use the Dept_Id_FK from the current
    record of the EMP table to display corresponding records of Dept table. I have a view object called DeptView in my Business
    Components which selects all the records from the Dept table.
    How do I get the value of Dept_Id_FK and use it to display the required records of the Dept table?
    I tried to declare a variable and get the value of Dept_Id_FK but it did not work. My code is as follows:
    <%! String m_DeptId = null; %>
    <jsp:useBean id="RowViewer" class="oracle.jbo.html.databeans.ViewCurrentRecord" scope="request">
    <%
    RowViewer.initialize(pageContext, "EMPApp_EMP_EMPAppModule.EMPView1");
    RowViewer.setReleaseApplicationResources(false);
    RowViewer.getRowSet().next();
    m_DeptId = (String)RowViewer.getRowSet().getCurrentRow().getAttribute("DeptIdFk");
    %>
    </jsp:useBean>
    Thanks.
    null

    First of all, Thank you very much for making use of the new topic format. It is very much appreciated.
    As for your question, I think there are several different ways to accomplish what I think you want to do.
    1. Create a view object that includes both Emp and Dept entities and join them there. In this case, your query would look something like this:
    Select e.empno,e.name,...,d.dname,d.loc from emp e, dept d
    where e.deptno = d.deptno
    You should be able to create a JSP off of this view object that contains both the employee and department information. In this case, BC4J takes care of the foreign key to primary key coordination.
    2. In order to set a dynamic where clause for a view, you need to do the following in your usebean tag:
    rsn.initialize(application,session, request,response,out,"DeptView");
    rsn.getRowSet().getViewObject().setWhereClause("deptno=" &#0124; &#0124; m_DeptId);
    rsn.getRowSet().getViewObject().executeQuery();
    rsn.getRowSet().first();
    You will need to do this in a separate usebean tag from the EmpView, since the usebean can only initialize one view object.
    In other words, you would have your ViewCurrentRecord bean tag for the EmpView, then a separate one for the DeptView where you use the above code to set the where clause to display just the information for the department you want.
    Another option, but one I'm not sure would work as well, is to create a master-detail JSP to do this for you. Usually a master-detail is a one-to-many (one department to many employees). Your request appears to be the reverse, but might still be doable using the same mechanism.
    You set up relationships between views in your BC4J project using View Links. If you used the BC4J project wizard and created default views, some of these links may have been created for you. They are created when BC4J detects a foreign key to primary key relationship in the database.
    You can create your own View Links using the View Link wizard. Select your BC4J project node and choose Create View Link... from the context menu. You will be asked to select a source view (Emp), and a target view (Dept), then select the attribute in each view that related the two of them (deptno).
    Next, you need to reflect this new relationship setting in your application module. Select your app module and choose Edit from the context menu. On the data model page, select the EmpView node in the Selected list. Now select the DeptView node in the available list and shuttle it over. You should see DeptView1 via yourlink appear indented under the EmpView node. Save and rebuild your BC4J project to reflect the changes.
    In your JSP project, you can now have the wizard create a master-detail form for you based on DeptView1.
    Let me know if the above answers your question, or if I have misunderstood what it is you wanted to do.
    null

  • How to edit the where clause of View object in search example dynamically

    Hi,
    I am new to OA Framework. Can anybody please tell me how can I assign the where clause dynamically. I want to search only those rows whose creation date is between a 'Date form' and 'Date to' inputs from the search page
    Thanks
    Anupam

    user567342 ,
    I will advice u again pls refer dev guide, there u can find code sample for ur requirement, which can be accomplished using stringbuffer.
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to change a prospect status to customer in BP,when the prospect turns out to be a potential customer?Please help me with the details.

    How to change a prospect status to customer in BP,when the prospect turns out to be a potential customer?Please help me with the details.
    Moderation: Kindly search before you post

    Dear Ramesh,
    Using Account life cycle we can record the different stages of a BP.
    But at any point of time we can hold one Stage at Business partner.and once we change status Prospect ro Customer. We can't able to see Prospect Status in that BP.
    Ex -
    Stage A- Potentail
    Stage B- Prospect
    Stage C- Customer
    with the help of UI configuration we can define.
    Need your comment,
    Thx
    Karthik

  • Dynamically changing the WHERE clause in detail VO in Master Detail

    Hi, I want to develop a search functionality, results will be in a table, which will have an inline table displaying the details per row found.
    I have a MD defined trough viewlink. I do change the master VO at runtime (set the entire SQL), based on the criteria entered by the user.
    Is there a way to change the VO at the detail end of the link at runtime - that is what I haven't been able to do.
    I have read that the ADF framework creates internal VO for each master row, whenever accessed trough accessor (which is not I am trying to do). I haven't been able to find a way to get a hold of the REAL VO at the detail end and have its WHERE clause changed.
    Changes to the "VO instance in AM" (same one used as a definition in the detail end in the ViewLink def) does not seem to reflect the detail VO.
    I have a MasterView, DetailView, MasterDetailLink (MasterView->DetailView).
    MasterDetailLink is used to create a table with inline detail table. At runtime:
    1.get MasterView (from AM), change query trough setQuesry() - works.
    2.get DetailView (from AM), change query trough addWhereClause() - does not work (no exceptions) - the results I am getting DO NOT reflect the conditions of the where clause, I mean the clause have not been addedd.
    I 've looked at the logs (debug enabled) and it seems to me that there no "activities" related to the detail VO, even after the where clause of the VO from step 2 is changed.
    Looks like there is a separate VO which I would like to get a hold of :)
    Thanks, and sorry for the long explanation

    After you have added a new where clause on the detail VO, try re-executing VO's query by DetailVO.executeQuery()
    If it doesn't work try re-executing the MasterVO's query after you have added the where clause on the detail

  • How to get the column names of the table into the Dashboard prompt

    how to get the column names of the table into the Dashboard prompt
    Thanks & Regards
    Kishore P

    Hey john,
    My requirement is as follows
    I have created a Rank for Total sales by Region wise i.e RANK(SUM(Dollars By Region)) in a pivot table.
    My pivot table looks like this
    COLUMN SELECTOR: TOTAL US , REGION , DISTRICT , MARKET
    ---------------------------------------------------- JAN 2009          FEB 2009        MAR 2009
    RANK              REGION                  DOLLARS           DOLLARS        DOLLARS DOLLARS
    1 CENTRAL 10 20 30 40
    2 SOUTHERN 10 30 30 70
    3 EASTERN 20 20 20 60
    4 WESTERN 10 20 30 40
    When i select the District in column selector
    Report has to display rank based on Total Sales by District. i.e
    ------------------------------------------------- JAN 2009         FEB 2009       MAR 2009
    RANK             DISTRICT              DOLLARS           DOLLARS        DOLLARS DOLLARS
    for this i need to change the fx of rank i.e RANK(SUM(Dollars By Region)) to RANK(SUM(Dollars By District)) and fx of Region i.e Markets.Region to Markets.District dynamically.
    so , i need to capture column name of the value selected from the column selector and dynamically i need to update the fx 0f RANK & fx of region.
    do you have any solution for this?
    http://rapidshare.com/files/402337112/Presentation1.jpg.html
    Thanks & Regards
    Edited by: Kishore P on Jun 24, 2010 7:24 PM
    Edited by: Kishore P on Jun 24, 2010 7:28 PM

  • Is there a way to use dynamic built string in the "from" clause

    Hi all, im having one problem and now, im not sure how to solve it easily at all... :) Is there someone that would be so kind and put a eye on it? ..thx
    I have plsql proc, in which i have a list of table_names. For each of that table i need to run a query that will retrieve me a list of values and for each of that value i need to do something.
    If i can be more specific about the problem -> each of that table is built as key_column, value_columns, day,starttime. For a key per table there are 4 records per hour - every quarter. Im truncating those quarters to full-quarter (minutes => 0->14 = 0min; 15->29 = 15min, 30->44 = 30, 45->59=45)
    example
    i get for one key and specific hour four records at 15:01;15:16;15:31;15:46 => i truncate em to 15:00;15:15;15:30;15:45..Sometimes there is a problem with the tool that is generating those data for me, and one quarter could be moved a little - so i get data like 15:01;15:16;15:29;15:46 => after i truncate the times i get duplicates in second quarter. It also can happen like this : 23:00; 23:14; 23:29; 23:44; 23:59 => totaly bad => cos the last one supposed to be as 0:00 next day, ..and 23:14 as 23:15...So...that was a problem - and solution -> i wanted to create plsql that will find those hours in each table i ve defined, and for each problem hour i make some fixes - update the bad time ...
    ..and i have problem - can i put an dynamic built table_name in the "from" clause?
    example how i wanted to do that:
    declare
         type t_objectName     is table of varchar2(030) index     by pls_integer;
         l_tableName              t_objectName;
    begin
    l_tableName(1) := 'tmphlrgl';
    l_tableName(2) := 'tmprcfgl';
    l_tableName(3) := 'tmprcfbs';
    l_tableName(4) := 'tmpvlrgl';
    for i in (select evtime from (select day,trunc_quarter(evtime) evtime,m_id from l_tableName(i) group by day,trunc_quarter(evtime),m_id having count(*)>1) order by evtime) loop
    --some other conditions and the update...
    end loop;
    end;
    /I cannot use the l_tableName(i) for FROM ...get an error...I was thinking to build it as dynamic sql and execute immediate into some kind of object that can store mutliple lines, from which i would in the FOR cycle get the data...But im not sure if this could be done in plsql...
    thanks for your time and help..
    d.

    declare
    c sys_refcursor;
    begin
    for i in 1..4 loop
    open c for 'day,trunc_quarter(evtime) evtime,m_id
    from ' || l_tableName(i) ||
    'group by day,trunc_quarter(evtime),m_id having
    count(*)>1) order by evtime';Just to high light SELECT is missing that all
    OPEN c FOR ' SELECT day,trunc_quarter(evtime) evtime,m_id
              FROM' || l_tableName(i) ||
    'GROUP BY day,trunc_quarter(evtime),m_id  HAVING  count(*)>1)   ORDER BY evtime';

  • Re: [iPlanet-JATO] How to make an OR in the WHERE clause of a SELECT

    Harry,
    If you get a reference to your model, you can set the
    whereClauseOverride with exactly the string you want to use. Keep in
    mind that you are dealing with a the raw SQL where clause, therefore,
    you must use the actual table column names and not the model's logical
    field names as they could be different.
    QueryModelBase queryModel = (QueryModelBase)getModel(PersonModel.class);
    // you must add the "WHERE" as well
    String whereClause = "WHERE firstName LIKE '%max' OR lastName LIKE '%max%'";
    queryModel.setWhereClauseOverride(whereClause);
    Keep in mind that this will override all where criteria: static and
    dynamic where criteria. Static criteria can be declared in your model
    class: setStaticWhereCriteriaString(STATIC_WHERE_CRITERIA).
    You could optionally get the entire SQL statement and replace the
    __WHERE__ token yourself with a string replace technique. In fact, if
    you want to add an ORDER BY, you will need to get the SQL and append to
    the end.
    queryModel.getSelectSQL();
    Hope this helps. Let me know if you have any questions
    craig
    hlamer wrote:
    Hi,
    if I add criterias to my model
    with "SelectQueryModel.addUserWhereCriterion()" they will be concated
    with AND.
    How can I add a criteria with OR?
    I want something like:
    SELECT personId, firstName, lastName
    FROM Person
    WHERE firstName LIKE "%max"
    OR lastName LIKE "%max%"
    Thanks.
    Harry
    For more information about JATO, including download information, please visit:
    http://developer.iplanet.com/tech/appserver/framework/index.jsp

    Rewritten your query wuth tags as well
    &#123;code&#125;select  "P_CIRCUITS_FIBER"."PORTS_1",
            "P_CIRCUITS_FIBER"."PORTS_2",
            CASE WHEN CPORT.ID = (select REGEXP_SUBSTR(ports_1,'[^,]+',1,1) from p_circuits_fiber)
                 THEN "CPORT"."PORT_NO" END PORT_NO_1,
            CASE WHEN CPORT.ID = (select REGEXP_SUBSTR(ports_2,'[^,]+',1,1) from p_circuits_fiber)
                 THEN "CPORT"."PORT_NO" END PORT_NO_2
    from    "CPORT",
            "P_CIRCUITS_FIBER"
    where   p_circuits_fiber.fiber_id = :P4000_CIRCUIT_NO
    and     (select REGEXP_SUBSTR(ports_1,'[^,]+',1,1) from p_circuits_fiber) = "CPORT"."PORT_NO"  "PORT_NO_1"
    and     (select REGEXP_SUBSTR(ports_2,'[^,]+',1,1) from p_circuits_fiber) = "CPORT"."PORT_NO"  "PORT_NO_2"&#123;code&#125;
    Now we can see two columns references which should not be there.
    I even not sure to understand why those two conditions are in the WHERE clause. But for sure, CPORT.ID cannot be equal to two values unless they are same.
    Is there only one row in p_circuits_fiber ?
    Nicolas.

  • Saving result from sp_executesql into a variable and using dynamic column name - getting error "Error converting data type varchar to numeric"

    Im getting an error when running a procedure that includes this code.
    I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql
    DECLARE @retval AS DECIMAL(12,2)
    DECLARE @MonthVal VARCHAR(20), @SpreadKeyVal INT
    DECLARE @sqlcmd AS NVARCHAR(150)
    DECLARE @paramdef NVARCHAR(150)
    SET @MonthVal = 'Month' + CAST(@MonthNumber AS VARCHAR(2) );
    SET @SpreadKeyVal = @SpreadKey; --CAST(@SpreadKey AS VARCHAR(10) );
    SET @sqlcmd = N' SELECT @retvalout = @MonthVal FROM dbo.CourseSpread WHERE CourseSpreadId = @SpreadKeyVal';
    SET @paramdef = N'@MonthVal VARCHAR(20), @SpreadKeyVal INT, @retvalout DECIMAL(12,2) OUTPUT'
    --default
    SET @retval = 0.0;
    EXECUTE sys.sp_executesql @sqlcmd,@paramdef, @MonthVal = 'Month4',@SpreadKeyVal = 1, @retvalout = @retval OUTPUT;
    SELECT @retval
    DECLARE @return_value DECIMAL(12,2)
    EXEC @return_value = [dbo].[GetSpreadValueByMonthNumber]
    @SpreadKey = 1,
    @MonthNumber = 4
    SELECT 'Return Value' = @return_value
    Msg 8114, Level 16, State 5, Line 1
    Error converting data type varchar to numeric.

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
    to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    >> I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql <<
    This is so very, very wrong! A column is an attribute of an entity. The idea that you are so screwed up that you have no idea if you want
    the shoe size, the phone number or something else at run time of this entity. 
    In Software Engineering we have a principle called cohesion that says a model should do one and only one task, have one and only one entry point, and one and only one exit point. 
    Hey, on a scale from 1 to 10, what color is your favorite letter of the alphabet? Yes, your mindset is that level of sillyity and absurdity. 
    Do you know that SQL is a declarative language? This family of languages does not use local variables! 
    Now think about “month_val” and what it means. A month is a temporal unit of measurement, so this is as silly as saying “liter_val” in your code. Why did you use “sp_” on a procedure? It has special meaning in T-SQL.  
    Think about how silly this is: 
     SET @month_val = 'Month' + CAST(@month_nbr AS VARCHAR(2));
    We do not do display formatting in a query. This is a violation of at the tiered architecture principle. We have a presentation layer. But more than that, the INTERVAL temporal data type is a {year-month} and never just a month. This is fundamental. 
    We need to see the DDL so we can re-write this mess. Want to fix it or not?
    --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

  • How do I modify the WHERE clause in my SQL query?

    This seems like such a straight-forward part of the report design, but I'm fairly new to Crystal Reports and I only have experience with modifying reports someone else has already written.  In this particular case, I just need to modify the WHERE clause of the SQL query.  I can select Show SQL Query and see what statement is being used to select data, but I can't find where to modify it since it's grayed out.  I see how to change the selection criteria, parameters, grouping, etc...just not the WHERE clause.  The report is linked to a database used for reporting with a table created and populated by a stored procedure.  I don't need to modify the stored procedure because the data I want to filter by is currently in the table--I just don't know how to filter by what I need.  Here's part of the query:
    SELECT "rpt_dist"."startdate", "rpt_dist"."transtype", "rpt_dist"."laborcode", "rpt_dist"."crewid", "rpt_dist"."regularhrs" FROM   "Reporting"."dbo"."rpt_dist" "rpt_dist"
    WHERE  (rpt_dist."transtype" <> 'WORK' AND rpt_dist."transtype" <> 'WMATL') AND rpt_dist."laborcode" LIKE 'S%' AND (rpt_dist."crewid" = 'HOUS' OR rpt_dist."crewid" = 'HOUS2' ...
    I would like to add another crewid to the WHERE clause.  Thanks for any input.

    1.Open the report in the crystal designer
    2.Go to the field explorer(if hidden go to view menu->field explorer)
    3.Rt. click on the database fields->choose database expert
    4.Now you will see 2 columns-Available DataSource  and Selected Tables
    5.Rt. click on the object(ex.command) available in the Selected Tables column->Choose Edit command
    6.A new Modify Command window will appear,here you can edit your SQL Query
    I get to step 4 and I see the two columns including my database and the report table, but there is no command object available.  If I right-click on my table, I can just view the Properties. ??
    As for the other tip to modify the record selection:  I don't see anywhere the other crewid values are set and if I add the one I'm missing, it doesn't modify the existing SQL Query and when I preview the report it throws off the results so that no data displays??
    I'm using Crystal Reports 11.5 if that makes a difference.  Thanks again.

  • Pass values dynamically to the WHERE clause in SFAPI

    Hi there
    We have a requirement to pass values dynamically (in the run-time of the interface) to the WHERE condition to our SFAPI query.
    Eg -
    SELECT person, personal_information, address_information, phone_information, email_information, employment_information, job_information, compensation_information, paycompensation_recurring, paycompensation_non_recurring, job_relation, accompanying_dependent,         global_assignment_information, direct_deposit, national_id_card, person_relation
              FROM CompoundEmployee
              WHERE last_modified_on &gt;= to_date('LAST_RUN_DATE')  AND
                           last_modified_on &lt;= to_date('CURRENT_RUN_TIME') 
    LAST_RUN_DATE is stored in a custom entity for which we execute another OData query. The custom entity is updated with the CURRENT_RUN_TIME once the interface has been executed successfully. So the next time the interface is run it picks up the LAST_RUN_DATE from the custom OData entity.
    SAP PO has the functionality to run a dynamic query for OData adapters. Refer to Note 2051137 - PI Successfactors adapter : Dynamic odata query and single synchronous sfapi query
    Eg - select fields from position (this is what you state in OData query path in the comms channel; this is static); and you have an advanced tab in comms channel where you mention dynamicquery and set it to true (this points to a XSD which has the keyword TOP, SKIP & FILTER in it).
    This gets the filter values passed from the BPM from another query (from a OData cust_table).
    So the whole query is - select fields from position filter field a = x field b = y etc. Field a field b are fields in position that are you passing values x and y in run time of the interface.
    SAP PO also has the advanced tab feature for SFAPI for dynamic query.
    Question is -
    how to use it?
    has anyone implemented this before?
    What does XSD will look like?
    How do we pass values to the fields to the Where clause for SFAPI.
    Any ideas are welcome!
    Regards
    Arijit Das

    After you have added a new where clause on the detail VO, try re-executing VO's query by DetailVO.executeQuery()
    If it doesn't work try re-executing the MasterVO's query after you have added the where clause on the detail

  • Dynamic forms using dynamic column names

    I have a table with columns such as level_1, level_2, etc.
    until level_11 and I have another table with level_id and
    description, i.e. for level with id = 1 the description could be
    'Crawl.' Id 2 could be 'Walk' etc.
    I'm trying to make a checklist so people can mark when
    they've done things on the checklist, and then upload those values
    to the appropriate tables to store the information so it's all
    still there when they go back to check off a new skill.
    I can't figure out how to make the column names in the form
    dynamic.
    I've played around with the formatting and still can't quite
    get it. I've tried evaluate(queryname.level_#level_id#),
    queryname.label, a bunch of other ones, and I can't seem to get it
    to work.
    Thanks for the help!

    Get to know CF's structure / array notation. This comes in
    very handy when dealing with queries and form fields.
    - Form.myFieldName can also be referenced by
    Form["myFieldName"]
    - MyQuery.myField can also be referenced by
    MyQuery["myField"][rowNumber]
    Anything in the above example surrounded by quotation makes
    can be made dynamic by just adding in a cf variable surrounded by
    pound signs:
    get_dealer_completion["level_#level_id#"][1]

Maybe you are looking for