Using criteria on date ranges and ignoring times, best method

Where col.date is a date and time datatype, I know that by using:
trunc(col.date) between trunc(sysdate-10) and trunc(sysdate)
or
to_char(col.dat,'YYYYMMDD') between to_char(sysdate-10,'YYYYMMDD') and to_char(sysdate,'YYYYMMDD')
the results will include rows where col.date is between and including sysdate less 10 days and sysdate.
However, this means Oracle will not use any ordinary (ie not function based) index on the table.
I do not want to add another index (it's a transaction table with many transactions per second) and I would like to improve the speed of the query.
I know that it is close to use
col.date between sysdate-10 and sysdate+ (1-1/(60*60*24)) but this will cause missed data.
select sysdate-10 from dual
2007-01-20-14.03.44
But I want to include any transaction on 2007-01-20, before, during and after the time of 14.03.44.
Perhaps I have to either live with the speed problem or create a function based index on trunc(col.dated).
Any comments, thanks?

If you worry about index using why not to use <<datecolumn>> >= trunc(sysdate-10) and <<datecolumn>> < trunc(sysdate+1) ?
SQL> create table t (dt) as select sysdate+10-rownum from dict where rownum <=30;
Table created.
SQL> alter table t add primary key (dt);
Table altered.
SQL> set autotrace on
SQL> select dt from t where trunc(dt) between trunc(sysdate-10) and trunc(sysdate);
DT
20-JAN-07
21-JAN-07
22-JAN-07
23-JAN-07
24-JAN-07
25-JAN-07
26-JAN-07
27-JAN-07
28-JAN-07
29-JAN-07
30-JAN-07
11 rows selected.
Execution Plan
Plan hash value: 209346666
| Id  | Operation        | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT |             |    11 |    99 |     1   (0)| 00:00:01 |
|*  1 |  FILTER          |             |       |       |            |          |
|*  2 |   INDEX FULL SCAN| SYS_C005970 |    11 |    99 |     1   (0)| 00:00:01 |
SQL> select dt from t where dt >= trunc(sysdate-10) and dt < trunc(sysdate+1);
DT
20-JAN-07
21-JAN-07
22-JAN-07
23-JAN-07
24-JAN-07
25-JAN-07
26-JAN-07
27-JAN-07
28-JAN-07
29-JAN-07
30-JAN-07
11 rows selected.
Execution Plan
Plan hash value: 114909756
| Id  | Operation         | Name        | Rows  | Bytes | Cost (%CPU)| Time
|
|   0 | SELECT STATEMENT  |             |    11 |    99 |     1   (0)| 00:00:01
|
|*  1 |  FILTER           |             |       |       |            |
|
|*  2 |   INDEX RANGE SCAN| SYS_C005970 |    11 |    99 |     1   (0)| 00:00:01
|
--------------------------------------------------------------------------------Rgds.

Similar Messages

  • Moving multiple files by date range and/or file name filtered

    I need to move multiple files by date range and/or by filename (using a filter) to another directory. 
    OR
    How can I get the attributes of files in a directory, something you would see when typing in "dir" in a DOS or ls in UNIX.  I can parse this info and then make a array of files to move.
    The reason for needing this is that I need to move files that are located in another country, and sort them into different directories based on date.  Having to read each file for it's file information adds wasted time that I can't afford.  I am about to create a dos terminal to do a "dir" command to get the information and parse it out.. but I was hoping LV had a function that can get me that info so I don't have build it.
    THanks.

    You should use the 'File/Directory Info' functionality.
    This will return the last modificatoin of the file.
    Ton
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

  • Can we use the AdventureWorks2008R2 data for the real time project.

    Hi,
    In our project we are trying to do the data scrambling on First name, last name and middle name...
    In the regular practice we use to update the names as
    First Name = FN+<PERSON_SNO>
    Last Name = LN+<PERSON_SNO>
    Middle Name = MN+<PERSON_SNO>
    The Problem is the names are not looking realistic, so I thought of applying some logic and updating our PERSON table names based on Person.Person table in adventure works.
    My question is can we use the AdventureWorks2008R2 data for the real time project. Is there any cop right issue.
    Someone please help me solve this issue.
    Thanks
    Karthikeyan Jothi.

    Please read this link content:
    Adventure Works Sample Site
    sqldevelop.wordpress.com

  • Mailbox Export - Filtered for Date Range and Body Content

    I have been pulling my hair out with this one and hopefully someone can help.
    I need to search a mailbox and export all (sent & received) messages that fit in a date range and also have a specific word in the body. The query I am using doesn't seem to find the term at all, but the messages it does find fit within my date range,
    so part of it seems to work. The request was to not use wildcards too, only looking for the specific word in the body. Here is my one-liner...
    New-MailboxExportRequest -ContentFilter {(Body -like "Something") -and (Received -gt "07/01/2012") -and (Received -lt "07/31/2012") -or (Sent -gt "07/01/2012") -and (Sent -lt "07/31/2012")} -Mailbox "SearchMailbox"
    -Name "Label1" -FilePath \\server\temp\pst\Export.pst
    I've also tried to search for a common word like "the" just to make sure it wasn't a case of the term simply not being in mailbox. No dice.

    Hi,
    Agree with Nickeyclayton, you can use (body -like "*something*") instead of (body -like "something").
    I recommend you refer to the following article:
    Filterable Properties for the -ContentFilter Parameter
    Property
    Description
    Values
    Example syntax
    Body
    This   property returns messages that have the specified string within the message   body.
    String
    Wildcard
    -ContentFilter {Body -like   "*prospectus*"}
    Hope this helps!
    Thanks.
    Niko Cheng
    TechNet Community Support

  • Need JavaScript for Sharepoint Designer 2010, to show a Pop-up to all the users between date range and the redirect the site

    Dear all,
    I am very new to Sharepoint designer 2010. Its better to say, i am just stepping in.
    I have sharepoint site which is accessible for all the users to update few information. But i want this site not to be accessible during a date range, say from 15th to 20th of every month.
    I am planning to have something like this: If any user tries to access this sharepoint site between 15th to 20th date range of everymonth, then the browser must show an pop-up alert saying "This site is not accessible during this date range" and Redirect
    this sharepoint site to someother site (Say http:// somesitename.xx.com) immidiately.
    I know very little about how to add Javascript in sharepoint webpart.
    Please provide the Javascript or any best alternate solution to my concern.
    Thanks in advance.

    Hi,
    From your description, my understanding is that you want to redirect sharepoint site to another site between 15th and 20th every month.
    I agree with what Sudip says. If you still want to use JS code,You could try these steps
    below:
    Open your site with SharePoint Designer.
    Click Master Pages in left navigation.
    Find file v4.master, and backup it(it is very important).
    Right click your v4.master,
    choose "Edit File in Adavance Mode".
    Add the code below into the <head/> tag.
    <script src="https://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script><script
    type="text/javascript">
    $(document).ready(function(){
    var today = new Date();  
    var day = today.getDate(); // get current day
    var id = _spPageContextInfo.userid; // get the id of current logon in user
    var boolFlg = false;
    $.ajax({
       url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/SiteGroups/GetByName(\'"+"sharepoint Owners"+"\')/Users", //get users in a specified group can access the sharepoint site from 15th to 20th every
    month
       type: "GET",
       headers: {"accept": "application/json;odata=verbose"},
       success: function (data) {
          if (data.d.results) { 
             var src = data.d.results;
             for(var i = 0; i < src.length; i++){
                if(src[i].userid==id){ //check the logon in user in  the specified group or not
                   boolFlg = false;
                   break;
             if(!boolFlg){
                if(day <= 20 && day >=15){
                    alert("This site is not accessible during this date range"); // alert the message
                    location.href = "http:// somesitename.xx.com"; // redirect to another site
       error: function (xhr) {
          alert(xhr.status + ': ' + xhr.statusText);
    })</script>
    Best Regards
    Vincent Han
    TechNet Community Support

  • Difference Between Basic Date Scheduling and Lead Time Scheduling.

    Dear FRndz,
    Kindly help me out the difference between the Basic Date Scheduling and Lead Time Scheduling.
    Regards,
    SRini

    Dear,
    Basic scheduling :
    1.Basic dates are calculated.
    2.Exact to day.
    3.No cap reqmts are generated.
    4.Uses the inhouse production time from material master.
    5.Carried out automatically during planning run.
    In basic date calculation ( order start date/ order finish date ) the system always
    calculates backward scheduling.
    1. From the reqmts date the system subtracts the GR processing time to
    calculate the order fininsh date.
    2. From the order finish date the system subtracts the inhouse production time to calculate the order start date.
    3. From the order start date the system subtracts the opening period given in scheduling margin key to calculate the order opening date.
    Lead time scheduling :
    1.Exact to second
    2.ie production start date /time and finish date and time are calculated.
    3. cap reqmts are generated.
    4. uses times from routing.
    5. carried out only if the scheduling mode in MD02 screen is kept with indicator 2.
    From the order finish date the system subtracts the float after production to calculate the production finish date.
    From the production finish date the individual operations in the routing are scheduled backwards to calculate production start date.
    From the production start date the system subtracts the float before production
    to calculate order start date.
    Same thread.
    https://forums.sdn.sap.com/click.jspa?searchID=19281092&messageID=3548465
    Please refer this link,
    [Difference|scheduling]
    Hope clear to you.
    Regards,
    R.Brahmankar

  • Defining Date range and using the same range to search the documents.

    Hi Sap Gurus,
    in our business there are some documents which do have Validity period, like say Inspection certificates and valid for say 10 months, ex..  JAN 25th 2009 to Oct 24th 2009
    we store this certificate in DMS and link to some SAP object say an Asset,
    we have a requirement to list all the documents based on the expiry date range. say to get a list of documents which are about to expire in 15 days, or the list of documents which have already expired
    I tried to define a characteristic in date format, but it is a single value field, and search is only supported on that specific value only.
    like we cannot serch the DIR falling in between this Date Ranges.
    also report of Documents which are to expire in 15 days could not be got.
    is there a way to meet this requirement , if it is through a development also please tell me how the logic could be built
    Thanks and regards
    Priya S

    Hi SAP Gurus,
    Thanks much Thomas for your Promt reply.
    The solution provided by Thomas really works but the same thing is not possible in EDMS,
    in Easy DMS we cannot manually give any value in the date characteristics field, the system will ask to fill from the date window format.
    so we cannot enter < or > <> value in characteristics, hope there is any note or other procedure to get the same funtionality.
    please if any one worked on the same with EDMS  let me know
    Thanks and kind regards
    Priya S

  • Get Process Order List Based on Date Range and Order Status

    Hi all,
    Iam using BAPI_PROCORD_GET_LIST to get the entire list of Process Orders based on selection criteria as plant. However I have noticed that there's no selection option to get records between start and finish times neither does any option exists to get only the released or open orders.
    To filter records based on Start Date/Finish date or get records with specific status, we need to get the entire list of records that exists for a plant and then use repeater/condition action to filter the same. Fetching the complete list and then filtering is an overhead. Does anyone know a solution to this or does anyone have been in this situation ? Is there any other BAPI that supports the filter criteria to get open/released orders from SAP. Do we need to modify the BAPI to include Process Order start date and end date or System status as selection options ?
    Appreciate your help !
    Regards,
    Gilmour

    Hi Gilmour
    I would say you have 2 options here..
    1. Create a new RFC with the search params as you want them. Write the logic accordingly.
    2. Use the Enterprise services for Production Order where you can say you want Process Orders. The Service that has Planned Start Date and End Date along with Status is ProductionOrderSimpleByElementsQuery_sync. See Link [here|http://esworkplace.sap.com/socoview(bD1lbiZjPTAwMSZkPW1pbg==)/render.asp?id=D507C16176BE11DA36BB000F20DAC9EF&fragID=&packageid=DE0426DD9B0249F19515001A64D3F462&iv=]
    This service is available from ECC 600 onwards.
    You can call the Enterprise Services using the Web Service Action block.
    Regards
    Partha

  • Use formula for date range instead of parameter?

    I am designing a Crystal report that will always pull records for the next full week.
    Example:  Today is 8/4, so I need the report to pull data for dates 8/11 through 8/15.
    Currently, I am using parameters each time to run this report.
    Is there a formula that could automatically pull this date range without using parameters in my report?
    Any help is appreciated.
    Thanks.

    This is actually not too difficult.  Assuming you want to be able to run this on any date and get the "Next Full Week" starting on Monday (based on your date range above), here's what you could do:
    1.  Create a formula that I'll call {@StartDate}
    NumberVar dow := DatePart('w', CurrentDate, crMonday) - 1;  //Day of week, starting on Monday.
    NumberVar days := 7 - dow;
    CurrentDate + days
    2. Create a formula that I'll call {@EndDate}:
    {@StartDate} + 7
    3.  In the Select Expert, manually edit the selection formula to use these date formulas instead of the parameters.
    -Dell

  • Using a SQL data source and XML data source in the same template

    I am trying to develop a template for the Request for Quote report generated in Apps 11.5.10. I have loaded the data from the XML output into the template, but I am missing one field - I need the org_id from the po_headers table. Is it possible to use a sql data source (i.e., "select org_id from po_headers_all where po_header_id = [insert header_id from xml data]...") in addition to the xml data source to populate the template at runtime? When you use the Insert > SQL functionality is it static at the time the template is created, or does it call to the database at runtime? I've looked through all the docs I could find, but this isn't clear.
    Thanks for any help or suggestions you may have.
    Rhonda

    Hi Pablo
    Thats a tough one ... if you go custom with a data template you will at least get support on the data template functionality ie you have a problem when you try and build one. You will not get support on the query inside the data template as you might have gotten with the Oracle Report, well you could at least log a bug against development for a bad query.
    Eventually that Oracle Report will be converted by development anyway, theres an R12 project going on right now to switch the shipped OReports to data templates. AT this point you'll be fully supported again but:
    1. You have to have R12 and
    2. You'll need to wait for the patch
    On reflection, if you are confident enough in the query then Oracle will support you on its implementation within a data template. Going forward you may be able to swap out your DT and out in the Oracle one without too much effort.
    Regards, Tim

  • Support date range and as of date in Universe

    Hi,
    I have some questions on Universe design best practices. Can you please help ?
    We are using BO4 SP7 and UDT for universe design.
    Little bit on our schema: snow flake schema with multiple fact tables. Most of our table are 'Pure Type 6' dimension tables in which start date and end date are used to track historical data.  We also have date dimension table. We want to support both 'As of date' and custom 'date range' type reporting.
    Out typical use cases are like
    1. All items As of date
    2. All items between dates etc.
    How can we model it in the Universe ?
    1. We can not join every dimension with date_d dimension. So we have decided to put default conditions at Folder level. Our typical date conditions as below.
    date_d.end_full_date_utc  between  diminetion1_d.start_date AND diminetion1_d.end_date
    But problem is, table condition are not always applied. If we have A, B and C folders and if I create report by using objects from A and C then non of the condition applied to B appears in the query. This is problem for us.
    2. Other approach we thought is to define start and end prompt and define a restriction condition  for each and every table.
          diminetion1_d.start_date > [start_date_prompt] AND diminetion1_d.end_date < [end_date_prompt]
    We thought it will be too munch work as we have more than 150 tables and also 2 prompts will always appear, even of as of date, which may not look good.
    3. Is there a way apply to apply these date conditions at the individual table level so that they will appear in Query when ever the table is involved in the join path ?
    3. What is the best way to handle this kind of requirements, please suggest ?
    Thanks

    Hi,
    I have some questions on Universe design best practices. Can you please help ?
    We are using BO4 SP7 and UDT for universe design.
    Little bit on our schema: snow flake schema with multiple fact tables. Most of our table are 'Pure Type 6' dimension tables in which start date and end date are used to track historical data.  We also have date dimension table. We want to support both 'As of date' and custom 'date range' type reporting.
    Out typical use cases are like
    1. All items As of date
    2. All items between dates etc.
    How can we model it in the Universe ?
    1. We can not join every dimension with date_d dimension. So we have decided to put default conditions at Folder level. Our typical date conditions as below.
    date_d.end_full_date_utc  between  diminetion1_d.start_date AND diminetion1_d.end_date
    But problem is, table condition are not always applied. If we have A, B and C folders and if I create report by using objects from A and C then non of the condition applied to B appears in the query. This is problem for us.
    2. Other approach we thought is to define start and end prompt and define a restriction condition  for each and every table.
          diminetion1_d.start_date > [start_date_prompt] AND diminetion1_d.end_date < [end_date_prompt]
    We thought it will be too munch work as we have more than 150 tables and also 2 prompts will always appear, even of as of date, which may not look good.
    3. Is there a way apply to apply these date conditions at the individual table level so that they will appear in Query when ever the table is involved in the join path ?
    3. What is the best way to handle this kind of requirements, please suggest ?
    Thanks

  • Help to read a table with data source and convert time stamp

    Hi Gurus,
      I have a req and need to write a ABAP prog. As soon as i excute ABAP program it should ask me enter a data source name, then my ABAP prog has excute teh code, in ABAP code i have to read a table with this data source as key, sort time stamp from table and should display the data source and time stamp as output.
    As follows:
    Enter Data Source Name: 
    Then user enters : 2lis_11_vahdr
    Then out put should be "Data source  :"  10-15-2008.
    The time stamp format in table is 20,050,126,031,520 (YYYYMMDDhhmmss). I have to display as 05-26-2005. Any help would be apprciated.
    Thanks,
    Ram

    Hi Jayanthi Babu Peruri,
    I tried to extract YEAR, MONTH, DAY separately and using
    EDIT MASK written it.
    Definitely there will be some STANDARD CONVERSION ROUTINE will be there. But no idea about it.
    DATA : V_TS      TYPE TIMESTAMP,
           V_TS_T    TYPE CHAR16,
           V_YYYY    TYPE CHAR04,
           V_MM      TYPE CHAR02,
           V_DD      TYPE CHAR02.
    START-OF-SELECTION.
      GET TIME STAMP FIELD V_TS.
      V_TS_T = V_TS.
      CONDENSE V_TS_T.
      V_YYYY = V_TS_T.
      V_MM   = V_TS_T+4(2).
      V_DD   = V_TS_T+6(2).
      V_TS_T(2) = V_MM.
      V_TS_T+2(2) = V_DD.
      V_TS_T+4(4) = V_YYYY.
      SKIP 10.
      WRITE : /10 V_TS," USING EDIT MASK '____-__-________'.
              /10 V_YYYY,
              /10 V_MM,
              /10 V_DD,
              /10 V_TS_T USING EDIT MASK '__-__-__________'.
    If you want DATE alone, just declare the length of V_TS_T as 10.
    Regards,
    R.Nagarajan.
    We can -

  • Using NAST WITH DATE RANGE THE ZPROGRAM GIVING DUMP

    Hi Frineds,
    i am  writing select query from  NAST table for PO created time based on date range more than 10 days the program is giving DUMP in Quality System.. but in Developement system the dump is not coming for same date range.
    please see the below code......that i ahve written. help me.
    IF SY-SUBRC EQ 0.
        SELECT KAPPL
           OBJKY
           KSCHL
           SPRAS
           ERDAT
           ERUHR
           FROM NAST
           INTO TABLE IT_NAST
            WHERE KAPPL = 'EF' AND
                  OBJKY IN R_OBJKY AND
                   KSCHL IN S_KSCHL
                  AND ERDAT IN S_DATE
                  AND ERUHR IN  S_ERUHR.
        SORT IT_NAST  BY OBJKY.
        DELETE ADJACENT DUPLICATES FROM IT_NAST COMPARING OBJKY.
      ENDIF.
    ENDIF.
    regards,
    Vijay
    Edited by: Rob Burbank on Jan 21, 2010 12:42 PM

    Hi,
    thanks for your mail..
    the dump message
    There is no help text for this dump
    Either the text was inadvertently deleted or the release of
    the kernel differs from the release of the database
    Refer to the Note system for further information on            this dump.
    Regards,
    Vijay

  • SUMIFS with Date Range and Condition

    Hi, I have search in the forums and read the online numbers guide but can't seem to get the formular working in Numbers.
    I want to sum up a column of durations, if they are in between 2 dates and meet the condition to belong to one project. I have the following table:
    project
    total duration
    project
    start
    end
    duration
    date range start
    date range end
    one
    0
    one
    02.01.2013
    02.01.2013
    15:30
    01.01.2013
    31.01.2013
    two
    0
    one
    03.01.2013
    03.01.2013
    15:30
    three
    two
    04.01.2013
    04.01.2013
    15:30
    four
    two
    05.01.2013
    05.01.2013
    15:30
    five
    three
    06.01.2013
    06.01.2013
    15:30
    six
    three
    07.01.2013
    07.01.2013
    15:30
    seven
    three
    08.01.2013
    08.01.2013
    15:30
    I have the following formular but it does not give me any value: =SUMIFS(F,C,A5,D"≥"$G$2,E"≤"$H$2)
    What am I doing wrong
    Thank you for your help.

    Hi Barry,
    thank you very much for your detailed reply.
    The first difference I spot is that my duration is in hours:minutes 00:00 but this should not make a difference, right? I attach you here some sample data:
    Project
    Start date
    Start time
    End date
    End time
    Duration
    Project 1
    07.01.2013
    11:00
    07.01.2013
    11:42
    00:42
    PINC: 1
    07.01.2013
    16:11
    07.01.2013
    17:11
    01:00
    Theatro
    07.01.2013
    19:50
    07.01.2013
    19:54
    00:03
    Project 3
    08.01.2013
    11:19
    08.01.2013
    13:30
    02:11
    Project 1
    09.01.2013
    12:32
    09.01.2013
    13:02
    00:30
    PINC: 1
    09.01.2013
    17:55
    09.01.2013
    18:29
    00:34
    Project 3
    09.01.2013
    18:29
    09.01.2013
    19:36
    01:06
    And I will go through my formular again and check if everything is correct.
    Many greets, Andreas

  • Find intersections in date ranges and concatenate aggregated labels

    Hello All,
    The original source of data will be a table of persons with their member ship:
    Description StartDate EndDate
    18 Smith John Poker Club 01/01/2009 NULL
    18 Smith John Library 05/01/2009 18/01/2009
    18 Smith John Gym 10/01/2009 28/01/2009
    26 Adams Jane Pilates 03/01/2009 16/02/2009
    The challenge will be to find each intersection of membership date ranges for each person and produce for this each unique range:
    a new line with the StartDate and EndDate of the range
    Concatenate in the description the descriptions of the memberships for this range with:
    “/” as separator
    order by membership StartDate
    This is the table of results expected:
    18 Smith John Poker Club 01/01/2009 04/01/2009
    18 Smith John Poker Club / Library 05/01/2009 09/01/2009
    18 Smith John Poker Club / Library / Gym 10/01/2009 18/01/2009
    18 Smith John Poker Club / Gym 19/01/2009 28/01/2009
    18 Smith John Poker Club 29/01/2009 NULL
    26 Adams Jane Pilates 03/01/2009 16/02/2009
    Sample Script:
    SET DATEFORMAT dmy
    DECLARE @Membership TABLE (
    PersonID int,
    Surname nvarchar(16),
    FirstName nvarchar(16),
    Description nvarchar(16),
    StartDate datetime,
    EndDate datetime)
    INSERT INTO @Membership VALUES (18, 'Smith', 'John',
    'Poker Club', '01/01/2009', NULL)
    INSERT INTO @Membership VALUES (18, 'Smith', 'John',
    'Library', '05/01/2009', '18/01/2009')
    INSERT INTO @Membership VALUES (18, 'Smith', 'John',
    'Gym', '10/01/2009', '28/01/2009')
    INSERT INTO @Membership VALUES (26, 'Adams', 'Jane',
    'Pilates', '03/01/2009', '16/02/2009')
    Note:Make sure that your solution uses a single query that starts either with "SELECT" or "WITH" or ";WITH".
    Can you please share suggestions.
    Regards,
    Vaishu

    This query
    ;WITH RS AS -- RangeStart
    SELECT PersonID, StartDate AS RangeStart
    FROM @Membership
    UNION
    SELECT PersonID, DATEADD(day, 1, EndDate) AS RangeStart
    FROM @Membership
    WHERE EndDate IS NOT NULL
    RE AS -- RangeEnd
    SELECT PersonID, DATEADD(day, -1, StartDate) AS RangeEnd
    FROM @Membership
    WHERE StartDate IS NOT NULL
    UNION
    SELECT PersonID, EndDate AS RangeEnd
    FROM
    @Membership
    R AS -- Ranges
    SELECT RS.PersonID, RS.RangeStart, RE.RangeEnd
    FROM
    RS CROSS APPLY
    SELECT TOP (1) RE.RangeEnd
    FROM RE
    WHERE
    RE.PersonID = RS.PersonID
    AND (
    RE.RangeEnd >= RS.RangeStart
    OR RS.RangeStart IS NOT NULL AND RE.RangeEnd IS NULL
    ORDER BY
    ISNULL(RE.RangeEnd, '99991231')
    ) RE
    SELECT R.*,
    STUFF( (
    SELECT '/' + m.Description
    FROM
    @Membership m
    WHERE
    m.PersonID = R.PersonID
    AND (m.StartDate <= R.RangeEnd OR R.RangeEnd IS NULL) AND (m.EndDate >= R.RangeStart OR m.EndDate IS NULL)
    FOR XML PATH('')
    1, 1, '') AS Description
    FROM
    R
    Returns this result:
    PersonID
    RangeStart
    RangeEnd
    Description
    18
    2009-01-01
    2009-01-04
    Poker Club
    18
    2009-01-05
    2009-01-09
    Poker Club/Library
    18
    2009-01-10
    2009-01-18
    Poker   Club/Library/Gym
    18
    2009-01-19
    2009-01-28
    Poker Club/Gym
    18
    2009-01-29
    NULL
    Poker Club
    26
    2009-01-03
    2009-02-16
    Pilates
    EntityLite: A Lightweight, Database First, Micro ORM

Maybe you are looking for

  • Inspection lot creation during GR with respect to Purchase Order

    Dear Experts, Here is my Question Inspection lot creation during GR with respect to Purchase Order Inspection type 01 set in the material master inspection lot will be created during GR for a Purchase order from my understanding for every GR a inspec

  • X-refs and index markers in absolute paths don't work

    A problem has arisen that did not exist before: If I have added files to a book using an absolute path, all X-refs and index markers in those files then don't work. The index *generates* without trouble, but if I then try to Alt-click an item in the

  • Calling File/Windows Explorer from EBS 12i Form.

    Hello All, I am using BLOB store as SECUREFILE and everything is working perfect when called from .NET. Now requirement is create a Form (Oracle Form Developer 10g) running under EBS 12i. This Form will allow the user to select a file (from local or

  • Photoshop keeps crashing when I try to save

    Everytime I try to save my work the program crashes. No matter how small of a save. I have restarted my computer several times. What could be the problem?

  • Organizing my music

    I would like to create new folders in my iTunes. I can see how to create playlists, but I would like to have a folder to encompass several playlists. There doesn't seem to be any way to make a new folder in the iTunes source window. Does anyone know