Query to select values that match multiple ranges

Hi,
Oracle 10g.
I have a table POINTS(ID INTEGER, CLASS VARCHAR2(15), CUMUL NUMBER(2,1), ...).
In my application (APEX application), I show a list of point classes, order by cumul.
SELECT CLASS FROM POINTS ORDER BY CUMUL;Then user can choose some range of point classes (CUMUL is not shown in the application, it is just for the example) :
CUMUL     CLASS
12.2     31458     <- 
13.4     5S84     <-     range 1 
13.6     78PPH     <- 
15.0     3R594     <- 
15.1     ZB452 
15.5     54IO 
17.6     21GFD 
19.2     A54VV     <- 
19.9     IC112     <-     range 2 
20.8     158RC9     <- 
21.3     G4G5 
23.0     V22     <-     range 3For each range, I store only first and last classes selected by a user, in a table USER_SELECTION(ID, ID_USER, FROM_CLASS, TO_CLASS), so using the example above it would give :
ID     ID_USER          FROM_CLASS     TO_CLASS 
1     12          31458          3R594 
2     12          A54VV          158RC9 
3     12          V22          V22
...     ...          ...          ...The problem is that in a query, I need to return all points selected by a user, and I really don't know how to achieve that without too much work... :
SELECT *
FROM POINTS
WHERE USER_ID=12
AND CLASS IN ( *???* );
Any help would be much appreciated.
Yann.

It's not exactly clear what data is in what tables etc. but perhaps something like this...
select user_selection.id, points.*
from points, user_selection
where user_selection.user_id = 12
and   points.cumul between
      (select cumul from points where class = user_selection.class1)
      and
      (select cumul from points where class = user_selection.class2)
order by user_select.id, points.cumul

Similar Messages

  • Reorganize function will not allow "select rows that match"

    I'm trying to sort data in a sheet the same way excel lets you sort by using "filter"
    I'm told that using the Reorganize function will allow me to do this especially if I select the "select rows that match" options.
    The only problem is that that options is grayed out and I can't use it.
    Anybody else have any suggestions or instructions>?
    Thanks

    Make sure you have selected a table

  • Query in selected value for radiogroup

    Is it possible to have a query in the p_selected_value of an htmldb_item.radiogroup ?
    If yes, how ?
    If not, is it possible to always set the first radio button as the selected value ?
    thx,
    Patrick

    Hi Enric,
    After the execution of a query using Query designer, after the selection of the variable values, you will get navigation block and the data beside that in Data Analysis tab. In this navigation block, you will find only the restricted values after the variable selection. You will not find the values selected displayed over there. When you select a chracteristic and click on filter button, you will get the values which are restricted only within the data displayed beside that in the output.
    If you want to have a look at the variable selection parameter that you have selected in the popup, you should go to Information tab and you can check the same there.
    The Navigation Pane Web item shows the navigational state of a data provider. All the characteristics and structures of the data provider are listed. You can alter the navigation status by using drag and drop to drag characteristics or structures to an axis (rows or columns) of the table, or to remove them from the axis. Using drag and drop, you can swap the axes in the navigation area; the table changes accordingly. You can also drag characteristics to the filter pane using drag and drop.
    Hope this helps u...
    Regards,
    KK.

  • 'No authorization' error for selection values outside the authorized range

    Hi All,
    We are currently trying to use the authorization analysis concept for 'Cost center reporting'.
    We have made 0COSTCENTER info-object as authorization relevant and have created a analysis authorization object for it through RSECADMIN and we have maintained a single value as '1875' . We have assigned this object to 1 of the test users.
    So now if the user runs the report for cost center '1875' , he is able to view the data/report. Now if he enters any other cost center apart from '1875' than he gets an authorization error (Everything works as per requirement till this point).
    But now if the user enters multiple cost centers like 1875, 1876, 1877 as multiple single values and runs the report, he gets an 'No authorization error'.
    So all the experts, please let me know if it's possible in anyway for the user to see the result/report for the value he is authorized to (in this case - 1875) and should give an information/warning/error message saying that he is not authorized to other cost center (in this case - 1876, 1877).
    Same thing is occuring if user enters a range. Suppose a user is authorized for cost center - 1875 to 1880. Now if he puts multiple single values or range in between the authorized range than he can see the result but if he enters even 1 single value outside the range he gets an error - what I mean by this is - if the user enter a range from 1875 to 1801, he does not get any data display but instead he recieves an error message saying 'No authorization' even though he is authorized for all the cost centers in that range except 1801.
    I would really appreciate your help regarding this. Any comments/suggestions are very welcome.
    Thanks & regards,
    Sunny

    Hi Sunny
    That is the way analysis authorizations work!!
    If you ask for a number of values i.e. cost centers and you don't have authorization to *all* of them you will get a system error as you say.
    There is no way of partially evaluating the query as you suggest (only for the authorized values).
    Try to be less restrictive when defining characteristic values in RSECADMIN.
    In queries use variables with
    Processing by Authorization and Input Ready.
    So the system will tell the user which are the allowed values. In your example the system suggests the range 1875-1880.
    Hope this helps, regards
    Germá

  • Query help: query to return column that represents multiple rows

    I have a table with a name and location column. The same name can occur multiple times with any arbitrary location, i.e. duplicates are allowed.
    I need a query to find all names that occur in both of two separate locations.
    For example,
    bob usa
    bob mexico
    dot mexico
    dot europe
    hal usa
    hal europe
    sal usa
    sal mexico
    The query in question, if given the locations usa and mexico, would return bob and sal.
    Thanks for any help or advice,
    -=beeky

    How about this?
    SELECT  NAME
    FROM    <LOCATIONS_TABLE>
    WHERE   LOCATION IN ('usa','mexico')
    GROUP BY NAME
    HAVING COUNT(DISTINCT LOCATION) >= 2Results:
    SQL> WITH person_locations AS
      2  (
      3          SELECT 'bob' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
      4          SELECT 'bob' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
      5          SELECT 'dot' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
      6          SELECT 'dot' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
      7          SELECT 'hal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
      8          SELECT 'hal' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
      9          SELECT 'sal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
    10          SELECT 'sal' AS NAME, 'Mexico' AS LOCATION FROM DUAL
    11  )
    12  SELECT  NAME
    13  FROM    person_locations
    14  WHERE   LOCATION IN ('USA','Mexico')
    15  GROUP BY NAME
    16  HAVING COUNT(DISTINCT LOCATION) >= 2
    17  /
    NAM
    bob
    salHTH!
    Edited by: Centinul on Oct 15, 2009 2:25 PM
    Added sample results.

  • Query row structure to restrict on multiple ranges of Calendar Year /Month using Custom exit

    Hi All,
    I have written 2 queries in Bex 7.x which have similar requirement. One uses 0CALMONTH and other 0FISCPER. I will describe scenario with Calendar Year month query.
    Query to have user entry screen for 0CALMONTH. Added 0CALMONTH in Filters section and restricted on mandatory user entry variable.
    Key figures restricted in four ways by creating a row structure with four selections
    Current Month User entered value on selection screen (Restricted on User entry variable)
    Previous Month / Period (Above value offset -1)
    YTD value Range from Previous July / 07.YYYY to current user entered month value (Custom exit)
    LYTD value - Above value for previous year (Above value offset -12)
    For YTD value wrote a custom exit code which uses the user entry variable on 0CALMONTH to retrieve the current month value and then give output range value for YTD.
    The custom exit code when debugged seems to calculate the correct range. However the query output is not working and gives out the same data for Current month and YTD range. Also LYTD value and Previous month value don't show up with any data at all.
    Any tips on where we are going wrong would be helpful.
    Thanks!
    Custom Exit code:
    WHEN 'ZGB_FP_AYTD_PTNR'.
         IF i_step EQ '2'.
           READ TABLE i_t_var_range INTO loc_var_range WITH KEY vnam = 'ZFP_AYTD_PRTNR'
                                                                iobjnm = '0CALMONTH'.
           IF sy-subrc EQ 0.
             CLEAR: l_month_curr, l_month_low, l_year_curr, l_year_low,
                    l_calmonth_low, l_calmonth_high.
             l_month_curr = loc_var_range-low+4(3).
             l_year_curr = loc_var_range-low+0(4).
             l_month_low = 001.
             l_year_low  = l_year_curr.
             CONCATENATE l_year_low l_month_low INTO l_calmonth_low.
             CONCATENATE l_year_curr l_month_curr INTO l_calmonth_high.
             l_s_range-low = l_calmonth_low.
             l_s_range-high = l_calmonth_high.
             l_s_range-sign = 'I'.
             l_s_range-opt = 'BT'.
             APPEND l_s_range TO e_t_range.
           ENDIF.
         ENDIF.

    Hi
    try this code
    WHEN '0CALMONTH'.
    CLEAR: l_month_curr, l_month_low, l_year_curr, l_year_low,
                    l_calmonth_low, l_calmonth_high.
         IF i_step EQ '2'.
      loop at i_t_var_range INTO loc_var_range where vnam = 'ZFP_AYTD_PRTNR'.
             l_month_curr = loc_var_range-low+4(2).
             l_year_curr = loc_var_range-low+0(4).
             concatinate '0' l_month_curr into l_month_low.
             CONCATENATE l_year_low '001' INTO l_calmonth_low.
             CONCATENATE l_year_curr l_month_low INTO l_calmonth_high.
             l_s_range-low = l_calmonth_low.
             l_s_range-high = l_calmonth_high.
             l_s_range-sign = 'I'.
             l_s_range-opt = 'BT'.
             APPEND l_s_range TO e_t_range.
           endloop.
         ENDIF.
    This code used for calculate fiscal period interval from your input month.
    For Ex
    user input is 05.2014
    customer exit result as 001.2014 - 005.2014.
    Note: Fiscal year period is Jan - Dec otherwise need to convert the input month details.
    Regards
    Sureshkumar

  • Select function that returns multiple columns.

    Currently I have a function that will return 1 column and I can use that in a select statement. What I need is to return multiple columns from a table. In the function I have I return the street address from a table that holds information about dealers, I need to be able to also return the columns that contain the city, state, and zip code so it can be used in an sql select statement. How would I do this?
    My function:
    FUNCTION GET_ADDRESS(dealer_id IN number)
    RETURN tbl_dealer_info.c_street%TYPE AS
    v_rc tbl_dealer_info.c_street%TYPE;
    CURSOR get_dealer_cur IS
    SELECT c_street
    FROM tbl_dealer_info
    WHERE n_dealer_id = dealer_id;
    BEGIN
    v_rc := NULL;
    OPEN get_dealer_cur;
    FETCH get_dealer_cur INTO v_rc;
    IF get_dealer_cur%NOTFOUND THEN
    NULL;
    END IF;
    CLOSE get_dealer_cur;
    RETURN v_rc;
    EXCEPTION
    WHEN OTHERS THEN
    RETURN NULL;
    END GET_ADDRESS;
    My select statement:
    select GET_ADDRESS(1205) Street, DI.n_inactive_flag, DI.n_onhold_flag
    from tbl_dealer_info DI
    where DI.n_dealer_id = 1205;
    I would like to be able to select the street, city, state, and zip all in this select statement from the GET_ADDRESS function.
    Thanks,
    Lori Neirynck

    "The reality is you've probably already put your blinders on and you won't learn the best approach to solving your problem because you insist on asking a courtroom style question (just "yes" or "no" please)."
    Actually, I asked this question because I was looking for the best approach to my problem. I have an SQL statement that correctly selects everything it needs to from all 15 tables. The thing of it is it is very long and difficult to read. I wanted to try using functions so that I could change 12 AND/OR statements into 3 IF statements so everything is easier to read. I have received a couple of different ways to do this from other forums that assumed I knew what I was doing. I have gotten one to work, the other I'm still working on. I'll post the one that worked for others that want to know.
    SQL> insert into dealer_info values (1,'Me','13 success street', 'Wonder Town','Wonderland','1313');
    SQL> commit;
    SQL> create type t_address as object (
    2 street varchar2(100),
    3 city varchar2(30),
    4 state varchar2(30),
    5 zip varchar2(10));
    6 /
    Type created.
    SQL> create or replace function get_address (p_id number) return t_address
    2 is
    3 ret t_address := t_address(null,null,null,null);
    4 rec dealer_info%rowtype;
    5 begin
    6 select * into rec from dealer_info where id=p_id;
    7 ret.street := rec.street;
    8 ret.city := rec.city;
    9 ret.state := rec.state;
    10 ret.zip := rec.zip;
    11 return ret;
    12 end;
    13 /
    Function created.
    SQL> col name format a10
    SQL> col address format a70
    SQL> select name, get_address(id) address from dealer_info;
    NAME ADDRESS(STREET, CITY, STATE, ZIP)
    Me T_ADDRESS('13 success street', 'Wonder Town', 'Wonderland', '1313')
    1 row selected.
    -Lori

  • Query to select value for max date from a varchar field containing year and month

    I'm having trouble selecting a value from a table that contain a varchar column in YYYY-MM format. 
    ex.
    Emp_id Date Cost
    10264 2013-01 5.00
    33644 2013-12 84.00
    10264 2013-02 12.00
    33644 2012-01 680.0
    59842 2014-05 57.00
    In the sample data above, I would like to be able to select the for each Emp_id by the max date. Ex. For Emp_id 10264, the cost should be 12.00.

    create table test (Emp_id int, Date varchar(10), Cost decimal (6,2))
    insert into test values(
    10264, '2013-01', 5.00 ),
    (33644, '2013-12', 84.00 ),
    (10264, '2013-02', 12.00 ),
    (33644, '2012-01', 680.0 ),
    (59842, '2014-05', 57.00 )
    Select Emp_id,[Date],Cost FROM (
    select *,row_number() Over(Partition by Emp_id Order by Cast([Date]+'-1' as Datetime) Desc) rn
    from test)
    t
    WHERE rn=1
    drop table test

  • Select dates that match from same table.

    I wish to update a selection of records
    where the order_date is the same, and the customer_id is the same.
    The update simply need to be to change the order date on both to the lowest date of the two(or how ever many there are for that date).
    e.g.
    Ship_date / Order_date / customer_id
    1-02-01 2-01-01 1
    1-02-01 12-01-01 1
    12-01-01 1-01-01 2
    12-01-01 5-01-01 2
    ## So above the first 2 records would have the order_date set to the lowest date of the two records.
    A self join ?
    Not really sure about this, Thanks in advance!

    You could try this (not tested):
    UPDATE yourTable t1
    SET t1.Order_Date = (SELECT min(t2.Order_date)
                               FROM yourTable t2
                               WHERE t2.ship_date = t1.ship_date
                               AND t2.customer_id = t1.customer_id)However this also updates columns that already have the minimum value. Maybe you would like to avoid it, then add some where clause to the Update statement.
    Changed because order_date and ship_date needed to be switched.
    Message was edited by:
    Sven Weller

  • Query to select values greater than, where AS clause is used

    Oracle 10g
    Requesting your help in writing the query correctly.
    I have the following 2 tables. The AddProjectPhase and AddProject tables. It is many to many relationship. Each project can have a predefined set of 4 different phases under it. Each phase has a start date and an end date. I am writing a report to get the phases which have a duration greater than, for example, 3 months.
    The query below is working fine to just display the list of all the phases along with the duration of each phase. I am not able to modify it to select the phases which have a duration, for example, 3 or more months.
    CREATE TABLE  "ADDPROJECT"
       (     "VERSIONNO" NUMBER(*,0),
         "PROJID" VARCHAR2(20),
         "PROJNAME" VARCHAR2(60),
         "PROJSTARTDATE" DATE,
         "PROJSTATUS" VARCHAR2(20),
         "PROJENDDATE" DATE,
         "PROJENDTYPE" VARCHAR2(20),
         "PROJENDREASON" VARCHAR2(1000),
         "UCPROJECTMANAGER" VARCHAR2(20),
         "FROMDATE" DATE,
         "TODATE" DATE,
         "SRCHFIELD" VARCHAR2(20),
         "OPERATOR" VARCHAR2(20),
         "PARENTPROJID" VARCHAR2(20),
         "PROJHIDDENDATE" VARCHAR2(20),
          CONSTRAINT "PK_B36" PRIMARY KEY ("PROJID", "PROJHIDDENDATE") ENABLE
    CREATE TABLE  "ADDPROJECTPHASE"
       (     "VERSIONNO" NUMBER(*,0),
         "PROJPHASEID" NUMBER(9,0),
         "PHASESTARTDATE" DATE,
         "PHASEENDDATE" DATE,
         "RRDATE" DATE,
         "PHASENAME" VARCHAR2(30),
         "PROJPHASESTATUS" VARCHAR2(20),
         "PROJID" VARCHAR2(20),
         "OPERATOR" VARCHAR2(20),
         "FROMDATE" DATE,
         "TODATE" DATE,
         "SRCHFIELD" VARCHAR2(20),
         "REVIEWCOMMENTS" VARCHAR2(1000),
         "PROJHIDDENDATE" VARCHAR2(20),
         "ISUEVALUATION" NUMBER(1,0),
         "SOLUTIONINGTEAMINVOLVEMENT" NUMBER(1,0),
         "ISUNAME" VARCHAR2(20),
          CONSTRAINT "PK_A63" PRIMARY KEY ("PROJPHASEID") ENABLE
       )Below is the query to display the list of all the phases along with the duration of each phase which is working fine.
    SELECT pp.phaseName "phasename",
    pp.phaseStartDate "phaseStartDate",
    pp.phaseEndDate "phaseEndDate",
    pp.projPhaseStatus "projPhaseStatus",
    ap.projID "projID",
    ap.projName "projName",
    ap.projHiddenDate "projHiddenDate",
    ap.projStartDate "projStartDate",
    CASE
        WHEN pp.phaseEndDate IS NOT NULL
        THEN MONTHS_BETWEEN(1+pp.phaseEndDate,pp.phaseStartDate)
        WHEN pp.phaseEndDate IS NULL
        THEN MONTHS_BETWEEN(1+sysDate,pp.phaseStartDate)
        ELSE null
    END "phaseMonths"
    FROM AddProjectPhase pp, AddProject ap
    WHERE ap.projID = pp.projID
    AND ap.projHiddenDate = pp.projHiddenDate
    ORDER BY ap.projIDHowever the modified query shown below to select all the phases greater than, for example, 3 months, is resulting in
    ORA-00904: "PHASEMONTHS": invalid identifier SELECT pp.phaseName, pp.phaseStartDate, pp.phaseEndDate
    FROM AddProjectPhase pp, AddProject ap
    WHERE ap.projID = pp.projID
    AND ap.projHiddenDate = pp.projHiddenDate
    AND PhaseMonths IN
    (SELECT
    (CASE
    WHEN pp.phaseEndDate IS NOT NULL
    THEN MONTHS_BETWEEN(1+pp.phaseEndDate,pp.phaseStartDate)
    WHEN pp.phaseEndDate IS NULL
    THEN MONTHS_BETWEEN(1+sysDate,pp.phaseStartDate)
    ELSE null
    END) AS PhaseMonths
    FROM AddProjectPhase pp, AddProject ap
    WHERE ap.projID = pp.projID
    AND ap.projHiddenDate = pp.projHiddenDate)
    ORDER BY ap.projID

    Looking for this?
    select *
       from (
            SELECT pp.phaseName "phasename"
              , pp.phaseStartDate "phaseStartDate"
              , pp.phaseEndDate "phaseEndDate"
              , pp.projPhaseStatus "projPhaseStatus"
              , ap.projID "projID"
              , ap.projName "projName"
              , ap.projHiddenDate "projHiddenDate"
              , ap.projStartDate "projStartDate"
              , CASE WHEN pp.phaseEndDate IS NOT NULL THEN MONTHS_BETWEEN(1+pp.phaseEndDate,pp.phaseStartDate)
                     WHEN pp.phaseEndDate IS NULL     THEN MONTHS_BETWEEN(1+sysDate,pp.phaseStartDate)
                     ELSE null
                END "phaseMonths"
              FROM AddProjectPhase pp, AddProject ap
             WHERE ap.projID = pp.projID
               AND ap.projHiddenDate = pp.projHiddenDate
             ORDER
                BY ap.projID
      where "phaseMonths" >= 3

  • Struts: getting multiple selected values from a select element

    Hi Friends,
    I am a total newbie with struts,I have manage to run a simple login script,
    Now I was wonderingif there is a select box and user has the ability to select multiple values from it how do I get those values in the *Form class
    my select tag looks like this
    <html:select property="listboxValue" mulitple="mulitple">
    ...options--
    </html:select>
    in the ****Form extends ActionForm{....I have setter and getters for getting the value  from select box as below
    public void setListboxValue(String value){
    this.listboxValue = value;
    and the getter is
    public String getListboxValue(){
    return this.listboxValue ;
    please never mind the missing brackets and such.
    What I was hoping to get to work was something like this
    public void setListboxValue(String[] value){
    this.listboxValue = value;
    but that does not work...If I have the an array being passed,it seems like this method is no even envoked
    Please guide me
    Thanks

    I'm having trouble to get in the ActionForm all the selected values in my multiple select. I select all the values by setting to true the selected attribute of all the options in a javascript function. In the ActionForm the variable is String[]. I'm not getting any ClassCastException, but I only receive the first value selected (String array with just one element).
    Select definition:
    <html:select name="detalleConsultaForm" property="destinatarios" multiple="true" size="8" >
    Javascript function:
    function validalistarelacion(campo)
    {   if (campo.length < 1)
    alert("Campo sin valores");
    campo.select();
    return false;
    for (var i = 0; i < campo.length; i++)
    campo.options.selected = true;
    return true;
    ActionForm:
    String[] destinatarios;
    public String[] getDestinatarios() {
    return destinatarios;
    public void setDestinatarios(String[] destinatarios) {
    this.destinatarios = destinatarios;
    What I get:
    2006-03-30 12:54:19,899 [ExecuteThread: '10' for queue: 'weblogic.kernel.Default'] DEBUG BeanUtils - setProperty(es.tme.apl.mante
    nimientosPlanificados.form.DetalleConsultaForm@59def5, destinatarios, [2320])
    2006-03-30 12:54:19,899 [ExecuteThread: '10' for queue: 'weblogic.kernel.Default'] DEBUG ConvertUtils - Convert String[1] to class
    'java.lang.String[]'
    Thnx

  • Only get Users that match all Links

    Seemingly a very simple problem, but I can't seem to figure it out.
    Table below is a table that holds UserId' s and LinkId's.
    CREATE TABLE UserLink (UserId NUMBER, LinkId NUMBER );
    ALTER TABLE UserLink ADD PRIMARY KEY (UserId, LinkId);
    INSERT INTO UserLink VALUES (1, 1);
    INSERT INTO UserLink VALUES (1, 2);
    INSERT INTO UserLink VALUES (3, 1);
    INSERT INTO UserLink VALUES (4, 1);
    I'm looking for a query in which I can plug a List of LinkId's that outputs only users that have a relationship with ALL LinkId's provided.
    In this example you may assume that the List is equal to (1, 2), but you can't make any assumptions about the size of the list, other than size != 0.
    The query to find users that match ANY of the provided LinkId's is quite simple:
    SELECT UserId FROM UserLink
    WHERE LinkId IN (1,2)
    The correct query should output:
    USERID
    1
    And it should work for any size > 0 list of values.

    Here's one way:
    with ID_LIST as (select 1 LINKID from DUAL union all select 2 from DUAL)
    select distinct USERID from USERLINK a
    where not exists (
                      select LINKID from ID_LIST
                      minus
                      select B.LINKID
                        from USERLINK B
                       where B.USERID=a.USERID                  
    In 11g here is a different way using UNPIVOT to build the list of Link IDs.  This may be less cumbersome than a long UNION ALL list.
    with ID_LIST as (select  1 a,2 b from DUAL)
    select distinct USERID from USERLINK a
    where not exists (
                      select LINKID from ID_LIST UNPIVOT (LINKID for COL in(a,b))
                      minus
                      select B.LINKID
                        from USERLINK B
                       where B.USERID=a.USERID                  

  • How could I replace hard coded value in my sql query with constant value?

    Hi all,
    Could anyone help me how to replace hardcoded value in my sql query with constant value that might be pre defined .
    PROCEDURE class_by_day_get_bin_data
         in_report_parameter_id   IN   NUMBER,
         in_site_id               IN   NUMBER,
         in_start_date_time       IN   TIMESTAMP,
         in_end_date_time         IN   TIMESTAMP,
         in_report_level_min      IN   NUMBER,
         in_report_level_max      IN   NUMBER
    IS
      bin_period_length   NUMBER(6,0); 
    BEGIN
      SELECT MAX(period_length)
         INTO bin_period_length
        FROM bin_data
         JOIN site_to_data_source_lane_v
           ON bin_data.data_source_id = site_to_data_source_lane_v.data_source_id
         JOIN bin_types
           ON bin_types.bin_type = bin_data.bin_type 
       WHERE site_to_data_source_lane_v.site_id = in_site_id
         AND bin_data.start_date_time     >= in_start_date_time - numtodsinterval(1, 'DAY')
         AND bin_data.start_date_time     <  in_end_date_time   + numtodsinterval(1, 'DAY')
         AND bin_data.bin_type            =  2
         AND bin_data.period_length       <= 60;
      --Clear the edr_class_by_day_bin_data temporary table and populate it with the data for the requested
      --report.
      DELETE FROM edr_class_by_day_bin_data;
       SELECT site_to_data_source_lane_v.site_id,
             site_to_data_source_lane_v.site_lane_id,
             site_to_data_source_lane_v.site_direction_id,
             site_to_data_source_lane_v.site_direction_name,
             bin_data_set.start_date_time,
             bin_data_set.end_date_time,
             bin_data_value.bin_id,
             bin_data_value.bin_value
        FROM bin_data
        JOIN bin_data_set
          ON bin_data.bin_serial = bin_data_set.bin_serial
        JOIN bin_data_value
          ON bin_data_set.bin_data_set_serial = bin_data_value.bin_data_set_serial
        JOIN site_to_data_source_lane_v
             ON bin_data.data_source_id = site_to_data_source_lane_v.data_source_id
            AND bin_data_set.lane = site_to_data_source_lane_v.data_source_lane_id
        JOIN (
               SELECT CAST(report_parameter_value AS NUMBER) lane_id
                 FROM report_parameters
                WHERE report_parameters.report_parameter_id    = in_report_parameter_id
                  AND report_parameters.report_parameter_group = 'LANE'
                  AND report_parameters.report_parameter_name  = 'LANE'
             ) report_lanes
          ON site_to_data_source_lane_v.site_lane_id = report_lanes.lane_id
        JOIN (
               SELECT CAST(report_parameter_value AS NUMBER) class_id
                 FROM report_parameters
                WHERE report_parameters.report_parameter_id    = in_report_parameter_id
                  AND report_parameters.report_parameter_group = 'CLASS'
                  AND report_parameters.report_parameter_name  = 'CLASS'
             ) report_classes
          ON bin_data_value.bin_id = report_classes.class_id
        JOIN edr_rpt_tmp_inclusion_table
          ON TRUNC(bin_data_set.start_date_time) = TRUNC(edr_rpt_tmp_inclusion_table.date_time)
       WHERE site_to_data_source_lane_v.site_id = in_site_id
         AND bin_data.start_date_time     >= in_start_date_time - numtodsinterval(1, 'DAY')
         AND bin_data.start_date_time     <  in_end_date_time   + numtodsinterval(1, 'DAY')
         AND bin_data_set.start_date_time >= in_start_date_time
         AND bin_data_set.start_date_time <  in_end_date_time
         AND bin_data.bin_type            =  2
         AND bin_data.period_length       =  bin_period_length;
    END class_by_day_get_bin_data;In the above code I'm using the hard coded value 2 for bin type
    bin_data.bin_type            =  2But I dont want any hard coded number or string in the query.
    How could I replace it?
    I defined conatant value like below inside my package body where the actual procedure comes.But I'm not sure whether I have to declare it inside package body or inside the procedure.
    bin_type     CONSTANT NUMBER := 2;But it does't look for this value. So I'm not able to get desired value for the report .
    Thanks.
    Edited by: user10641405 on May 29, 2009 1:38 PM

    Declare the constant inside the procedure.
    PROCEDURE class_by_day_get_bin_data(in_report_parameter_id IN NUMBER,
                                        in_site_id             IN NUMBER,
                                        in_start_date_time     IN TIMESTAMP,
                                        in_end_date_time       IN TIMESTAMP,
                                        in_report_level_min    IN NUMBER,
                                        in_report_level_max    IN NUMBER) IS
      bin_period_length NUMBER(6, 0);
      v_bin_type     CONSTANT NUMBER := 2;
    BEGIN
      SELECT MAX(period_length)
        INTO bin_period_length
        FROM bin_data
        JOIN site_to_data_source_lane_v ON bin_data.data_source_id =
                                           site_to_data_source_lane_v.data_source_id
        JOIN bin_types ON bin_types.bin_type = bin_data.bin_type
       WHERE site_to_data_source_lane_v.site_id = in_site_id
         AND bin_data.start_date_time >=
             in_start_date_time - numtodsinterval(1, 'DAY')
         AND bin_data.start_date_time <
             in_end_date_time + numtodsinterval(1, 'DAY')
         AND bin_data.bin_type = v_bin_type
         AND bin_data.period_length <= 60;
      --Clear the edr_class_by_day_bin_data temporary table and populate it with the data for the requested
      --report.
      DELETE FROM edr_class_by_day_bin_data;
      INSERT INTO edr_class_by_day_bin_data
        (site_id,
         site_lane_id,
         site_direction_id,
         site_direction_name,
         bin_start_date_time,
         bin_end_date_time,
         bin_id,
         bin_value)
        SELECT site_to_data_source_lane_v.site_id,
               site_to_data_source_lane_v.site_lane_id,
               site_to_data_source_lane_v.site_direction_id,
               site_to_data_source_lane_v.site_direction_name,
               bin_data_set.start_date_time,
               bin_data_set.end_date_time,
               bin_data_value.bin_id,
               bin_data_value.bin_value
          FROM bin_data
          JOIN bin_data_set ON bin_data.bin_serial = bin_data_set.bin_serial
          JOIN bin_data_value ON bin_data_set.bin_data_set_serial =
                                 bin_data_value.bin_data_set_serial
          JOIN site_to_data_source_lane_v ON bin_data.data_source_id =
                                             site_to_data_source_lane_v.data_source_id
                                         AND bin_data_set.lane =
                                             site_to_data_source_lane_v.data_source_lane_id
          JOIN (SELECT CAST(report_parameter_value AS NUMBER) lane_id
                  FROM report_parameters
                 WHERE report_parameters.report_parameter_id =
                       in_report_parameter_id
                   AND report_parameters.report_parameter_group = 'LANE'
                   AND report_parameters.report_parameter_name = 'LANE') report_lanes ON site_to_data_source_lane_v.site_lane_id =
                                                                                         report_lanes.lane_id
          JOIN (SELECT CAST(report_parameter_value AS NUMBER) class_id
                  FROM report_parameters
                 WHERE report_parameters.report_parameter_id =
                       in_report_parameter_id
                   AND report_parameters.report_parameter_group = 'CLASS'
                   AND report_parameters.report_parameter_name = 'CLASS') report_classes ON bin_data_value.bin_id =
                                                                                            report_classes.class_id
          JOIN edr_rpt_tmp_inclusion_table ON TRUNC(bin_data_set.start_date_time) =
                                              TRUNC(edr_rpt_tmp_inclusion_table.date_time)
         WHERE site_to_data_source_lane_v.site_id = in_site_id
           AND bin_data.start_date_time >=
               in_start_date_time - numtodsinterval(1, 'DAY')
           AND bin_data.start_date_time <
               in_end_date_time + numtodsinterval(1, 'DAY')
           AND bin_data_set.start_date_time >= in_start_date_time
           AND bin_data_set.start_date_time < in_end_date_time
           AND bin_data.bin_type = v_bin_type
           AND bin_data.period_length = bin_period_length;
    END class_by_day_get_bin_data;

  • Which formula(a) do I use to select any value that is than 0 but 7 out of a range of cells and sum them.

    I'm working on a sheet that I want to use to select a specific part based on values created by the sum of values in other cells. I am down to the point where I need to select a low range of numbers
    If the sum of cell D5 equals any sum between 1-15 will equal = part 1
    If the sum of cell D5 equals any sum between 16-23 will equal = part 2 ,
    If the sum of cell D5 equal antsy sum between 24-32 will equal part 3.
    I'm at a loss how to make one formula or combination of formulas do this.
    Thanks in advance.
    Big Al Hur

    Hi Al,
    The confusion arises from your having asked two separate questions, one in the subject line, the other in the body of your initial post.
    1.
    How do I sum only the values greater than zero and less than 7 in a range of cells?
    This formula supplied by SGIII does what you have asked there:
    =SUMIFS(A,A,">0",A,"<7")
    The syntax is:
    SUMIFS(sum-values, test-values, condition, test-values, condition…)
    sum-values ( A ) is the range of cells containing the values to be summed (all the body cells in column A)
    test-values and condition come in pairs. the first names the range of values to be tested, the second names the condition that must be met.
    In this formula, the test-values in each pair are the same as the sum values.
    condition ( ">0" ) is the first condition that must be met by these values. (greater than zero)
    the second condition ( "<7" ) is the second condition that must be met (less than seven)
    To be included in the sum, a value in the list must meet both conditions: It must be greater than 0 AND less than 7. IN SG's example, there are two values that meet both conditions, 2 in A2 and 6 in A5, that meet both conditions. Their sum, 8, is shown in A10, whch is the cell containing the formula.
    2
    If the sum of cell D5 equals any sum between 1-15 will equal = part 1
    If the sum of cell D5 equals any sum between 16-23 will equal = part 2 ,
    If the sum of cell D5 equals any sum between 24-32 will equal part 3.
    This formula supplied by SGIII, and the Lookup table that goes with it, does what you have asked here.
    =VLOOKUP(D5,Lookup::A:B,2,close-match)
    Close-match means 'the largest value that is less than or equal to' the search-value.
    The search-value is the value in D5
    VLOOKUP searches in the leftmost column (A) of the lookup table (columns A and B of the table named Lookup).
    With "close-match" specified:
    any value that is equal to or greater than 0 and less than 16 will be matched by the 0 in A2. VLOOKUP will return the value in the same row of column 2 (B) of the table: "Part 1"
    any value that is equal to or greater than 16 and less than 24 will be matched by the 16 in A3. VLOOKUP will return the value in the same row of column 2 (B) of the table: "Part 2"
    any value that is equal to or greater than 24 will be matched by the 24 in A4. VLOOKUP will return the value in the same row of column 2 (B) of the table: "Part 3"
    While this is not an exact match with your description above, it will perform exactly as you requested IF the value in D5 is never less than 1 and never greater than 32.
    If the possible range is greater than that, I would suggest the changes shown below to the formula and to the lookup table. The column containing numbers is column D, and represents values in D5. Column E shows the result for each value using the given formula and lookup table (LU A). Column F shows results for the same values using the revised formula and lookup tble (LU B):
    Original                              =VLOOKUP(D,LU A :: A:B,2,1)
    Revised formula: =IFERROR(VLOOKUP(D,LU B :: A:B,2,1),"N//A")
    In the revision, IFERROR takes care of the negative values in D2 and D3. The zero value in D4 and in the last row of column D and the overflow values (greater than 32) are handled by the revisions to the lookup table.
    Regards,
    Barry

  • How to get all rows that are returned in inner sub query of select statemen

    If a sub query in select statement returns more than one row than how to get all those returned rows in the final
    output of the query .It will be all right if all column's value repeat and that multiple output of inner query comes
    in another column .
    How to get that ?

    As Frank said, you likely want a join, and likely an outer join to replicate the select in the projection. Something like:
    SELECT id,stat, section, USER_ID concerned_person
    FROM table_all,
      left join table2
        on room_id = sectoion and
           sur_role = 'r001'
    WHERE section IN (SELECT code
                      FROM t_area
                      WHERE dept= 'p002')An alternative, depending on where and how you are using the statement would be something like:
    SQL> WITH t AS (
      2    select 1 id from dual union all
      3    select 2 id from dual),
      4  t1 as (
      5    select 1 id, 'One' descr from dual union all
      6    select 1, 'Un' from dual union all
      7    select 1, 'Une' from dual)
      8  SELECT t.id, CURSOR(SELECT t1.id, t1.descr from t1
      9                      WHERE t1.id = t.id)
    10  FROM t;
                      ID CURSOR(SELECTT1.ID,T
                       1 CURSOR STATEMENT : 2
    CURSOR STATEMENT : 2
                      ID DESCR
                       1 One
                       1 Un
                       1 Une
                       2 CURSOR STATEMENT : 2
    CURSOR STATEMENT : 2
    no rows selectedJohn

Maybe you are looking for

  • HELP WITH ONLINE LOG IN

    Hi  I have recently split with my husband who was the named person on my orange mobile account. We have gone through the process of changing the account and direct debit details over to my name but i am now having trouble logging into my account onli

  • Irrelevant pictures

    How the heck does Spotlight work??? I did a search for "contact" and Spotlight came up with several images in the images category, none of which had the word contact anywhere in the filename (one was named 167672.jpg). What's more, none of the folder

  • For proxy any coding required

    i have never done any proxies so is there any coding required in ABAP part, i  am using ABAP proxies thanking you sridhar

  • Nivo slider on iWeb - can get it to work, but not on one Mac.

    I am a complete luddite when it comes to computers, but I have managed to set up a couple of pretty decent websites using iweb. I am looking for a bit of advice as to where I am going wrong setting up the Nivo slider on one of our computers though. H

  • 2008R2 DHCP MP

    I have the older DHCP MP for 2008R2 version 6.0.6709.0 and the main DHCP server library version 6.0.7063.0 with the 2012 and 2012 R2 also the same version. I don't see any data populating the server health or scope health views and none of the server