Split single row in multiple rows based on date range

I need sql script that can split single row in multiple rows based on start date and end date column in table.
Thank you

I agree to your suggestion of having a dates table permanently in the database. Thats how we also do for most of our projects as well
But in most projects the ownership  of table creation etc lies with the client as they will be the DBAs and will be design approval authorities. What I've seen is the fact that though
many of them are in favour of having calendar table they dont generally prefer having a permanent table for numbers in the db. The best that they would agree is for creating a UDF which will have
tally table functionality built into it based on a number range and can be used in cases where we need to multiply records as above.
Wherever we have the freedom of doing design then I would also prefer creating it as a permanent table with required indexes as you suggested.
>> many of them are in favour of having calendar table they dont generally prefer having a permanent table
Those people do not understand about database and are not DBAs :-)
It is our job to tell them what is right or wrong.
** This is a real story! I had a client several years back, who was the CEO of a software company.
He use the query:
select * from table_name
In order to get the last ID!
The table_name was actually a view that took data from several tables, and the main table that he wanted to get the ID included several string columns, with lot of data!
he actually pulled all this data to the application, just to get the lat ID in a specific table!
It is our job as Consultants or DBAs to fix's his misunderstanding :-)
  Ronen Ariely
 [Personal Site]    [Blog]    [Facebook]

Similar Messages

  • Displaying different sums in the same row based on date ranges

    Say I had a table like this
    DECLARE @t1 TABLE (RowId INT PRIMARY KEY IDENTITY(1,1), BusinessType VARCHAR(100), SalesPerson VARCHAR(100), Category VARCHAR(100), OrderAmount DECIMAL(10,2), OrderDate DATETIME )
    Now I want to get a result that is grouped first by BusinessType, then SalesPerson and include derived columns that are sums based  on different date ranges.
    Month-to-date = from the start of the current month to today
    Month-to-date previous year = from the start of the current month to today 1 year ago
    DECLARE @today DATETIME
    DECLARE @today_prev_year DATETIME
    DECLARE @year_start DATETIME
    DECLARE @year_prev_start DATETIME
    DECLARE @month_start DATETIME
    DECLARE @month_prev_start DATETIME
    SET @today = GETDATE();
    SET @today_prev_year = DATEADD(YEAR,-1,@today)
    SET @year_start = CAST('01/01/' + CAST(DATEPART(YEAR,GETDATE()) AS VARCHAR(10)) AS DATETIME);
    SET @year_prev_start = DATEADD(YEAR,-1,@year_start)
    SET @month_start = DATEADD(month, DATEDIFF(month, 0, @today), 0); --gets the first of the current month
    SET @month_prev_start = DATEADD(YEAR,-1,@month_start); --gets the first of the current month
    SELECT t.BusinessType,t.SalesPerson,t.Category
    SUM(CASE WHEN o.OrderDate > @month_start AND ac.DocumentDate < @today THEN o.OrderAmount ELSE 0 END) AS MTDActualAmount
    SUM(CASE WHEN o.OrderDate > @month_prev_start AND ac.DocumentDate < @today_prev_year THEN o.OrderAmount ELSE 0 END) AS MTDPrevActualAmount
    FROM @t1 t
    Hope this is clear as to what Im trying to do.  Im ultimately going to pull this into an SSRS report, so im wondering if I can do this different SUM values in the report and handle the grouping there.
    Thoughts?

    Based on your example (with a group by added) it should work.
    However, if you incorperated a calendar table (http://social.technet.microsoft.com/wiki/contents/articles/29260.tsql-calendar-functions-and-tables.aspx)
    you could lose all those manually set parameters:
    DECLARE @t1 TABLE (RowId INT PRIMARY KEY IDENTITY(1,1), BusinessType VARCHAR(100), SalesPerson VARCHAR(100), Category VARCHAR(100), OrderAmount DECIMAL(10,2), OrderDate DATETIME, DocumentDate DATETIME)
    INSERT INTO @t1 (BusinessType, SalesPerson, Category, OrderAmount, OrderDate, DocumentDate) VALUES
    ('A','Joe','CatA',10,'2015-01-01','2015-01-01'),('A','Joe','CatB',10,'2015-01-02','2015-01-01'),('A','Joe','CatA',30,'2015-01-03','2015-01-04'),('A','Joe','CatB',40,'2015-01-04','2015-01-01'),('A','Joe','CatA',100,'2015-02-01','2015-02-01'),
    ('A','Joe','CatB',100,'2015-02-02','2015-02-01'),('A','Joe','CatA',300,'2015-02-03','2015-02-04'),('A','Joe','CatB',400,'2015-02-04','2015-02-01'),('A','Bob','CatA',1,'2015-01-01','2015-01-01'),('A','Bob','CatB',1,'2015-01-02','2015-01-01'),
    ('A','Bob','CatA',3,'2015-01-03','2015-01-04'),('A','Bob','CatB',4,'2015-01-04','2015-01-01'),('A','Bob','CatA',10,'2015-02-01','2015-02-01'),('A','Bob','CatB',10,'2015-02-02','2015-02-01'),('A','Bob','CatA',30,'2015-02-03','2015-02-04'),
    ('A','Bob','CatB',40,'2015-02-04','2015-02-01'),('B','Joe','CatA',10,'2015-01-01','2015-01-01'),('B','Joe','CatB',10,'2015-01-02','2015-01-01'),('B','Joe','CatB',40,'2015-01-04','2015-01-01'),
    ('B','Joe','CatA',100,'2015-02-01','2015-02-01'),('B','Joe','CatB',100,'2015-02-02','2015-02-01'),('B','Joe','CatA',300,'2015-02-03','2015-02-04')
    SELECT t.BusinessType,t.SalesPerson,t.Category,
    SUM(CASE WHEN OrderDate >= monthStart AND DocumentDate < today THEN OrderAmount ELSE 0 END) AS MTDActualAmount,
    SUM(CASE WHEN OrderDate BETWEEN prevMonthStart AND prevMonthENd AND DocumentDate >= yearStart THEN OrderAmount ELSE 0 END) AS MTDPrevActualAmount
    FROM @t1 t
    INNER JOIN calendar c
    ON today = CAST(CURRENT_TIMESTAMP AS DATE)
    Group by t.BusinessType,t.SalesPerson,t.Category

  • Selecting single record from multiple record based on date

    Hi experts,
    I have a table which contains the multiple records for single ID No. Now i have to select single record which contains the latest date.
    here is the structure
    Name   Null Type        
    ID_P        NUMBER      
    NAME_P      VARCHAR2(12)
    DATE_P      TIMESTAMP(6)
    Records
    1 loosi     22-AUG-13 01.27.48.000000000 PM
    1 nammi  26-AUG-13 01.28.10.000000000 PM
    2 kk        22-AUG-13 01.28.26.000000000 PM
    2 thej      26-AUG-13 01.28.42.000000000 PM
    now i have to select below 2 rows how can write select qurie for this?
    1 loosi     26-AUG-13 01.27.48.000000000 PM
    2 thej      26-AUG-13 01.28.42.000000000 PM

    Hi,
    You can use the analytic ROW_NUMBER function.
    I don't have a copy of your table, so I'll use scott.emp to illustrate.  In scott.emp, there may be multiple rows for a single job.  To display just 1 row per job, the row with the most recent hiredate:
    WITH got_r_num AS
         SELECT  empno, job, deptno, hiredate -- Or whatever columns you want
         ,       ROW_NUMBER () OVER ( PARTITION BY  job
                                      ORDER BY      hiredate DESC
                                    )  AS r_num
        FROM    scott.emp
    --  WHERE ...   -- If you need any filtering put it here
    SELECT   *      -- Or list all columns except r_num
    FROM     got_r_num
    WHERE    r_num   = 1
    What results do you want in case of ties?  Depending on your requirements, you may want to add tie-breaking expressions to the analytic ORDER BY clause, and/or use RANK instead of ROW_NUMBER.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Point out where the query above is producing the wrong results, and explain, using specific examples, how you get the right results from the given data in those places.
    If you modify the query at all, post your modified version.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • During import, how to auto split one project into multiple albums based on date?

    I believe I've done enough aperture reserach to get all my terminology right, so here goes...
    I've created a file structure within the aperture inspector the the tune of: 
    Year [folder], Type of event (Occasion, special occasion, holiday, vacation) [folder], Project (Wedding), Album (i.e. Day 1, Day 2 or Pre wedding week, event, honeymoon).
    I also have entire months with 7 or 8 pictures each day, that are of the same type/project (random dog pictures) but are distinctly different days (albums - day in park, in bed at night, watching movie). 
    My question is, can I import one project with multiple albums already created based on the date they're taken.  As I can see it, all I can do is split individual projects automatically by date.  But what if one project is over one month, but has multiple distinct days that would be ideal for albums?  One more example.  We did a trip to San Fran.  One day was touring the city, one day was a concert, another day was touring the city.  All one project, but 3 different albums (in my mind).  I had to import as one project, then separately go in and make albums.  I would like that done automatically.
    My suspicion is that I can not natively do this within aperture, and that I would need something called an "applescript."  I haven't done any reserach into that area, so if that's the case and you know where I can find a script that would do this, I'd appreciate the help. 
    Sorry for the wordiness, just wanted to be clear.  Thanks for any and all help!

    Hi,
    You need to create a new requirement in tcode VOFM for that, together with your ABAP consultant. This requirement will be used in copy contol.
    http://saptechsolutions.com/pdf/VOFMCopyRequirementRoutines.pdf
    MdZ

  • Query to split one row to multiple based on date range

    Hi,
    I need to split single row into multple based on date range defined in a column, start_dt and end_dt
    I have a data
    ID      From date             End_dt                measure
    1        2013-12-01         2013-12-03            1
    1        2013-12-04         2013-12-06            2
    2        2013-12-01         2013-12-02            11
    3        2013-12-03         2013-12-04          22
    I required output as
    ID      Date                      measure
    1        2013-12-01              1
    1        2013-12-02              1
    1        2013-12-03              1
    1        2013-12-04              2
    1        2013-12-05              2
    1        2013-12-06              2
    2        2013-12-01             11
    2        2013-12-02             11
    3        2013-12-03             22
    3        2013-12-04            22
    Please provide me sq, query for the same
    Amit
    Please mark as answer if helpful
    http://fascinatingsql.wordpress.com/

    Have a calendar table for example and then probably using UNION ALL from date  and stat date JOIN the Calendar table
    SELECT ID,From date  FROM tbl
    union all
    SELECT ID,End_dt FROM tbl
    with tmp(plant_date) as
       select cast('20130101' as datetime)
       union all
       select plant_date + 1
         from tmp
        where plant_date < '20131231'
    select*
      from  tmp
    option (maxrecursion 0)
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Split Single IDOC into Multiple IDOC's Based on Segment Type

    Hi Experts,
    I have a scenario IDOC to FILE ,  Split Single IDOC into Multiple IDOC's based on Segment Type
    Outbound:
    ZIdocName
    Control Record
    Data Record
    Segment 1
    Segment 2
    Segment 3
    Status Record
    I should get output like below
    Inbound:
    ZIdocName
    Control Record
    Data Record
    Segment 1
    Status Record
    ZIdocName
    Control Record
    Data Record
    Segment 2
    Status Record
    ZIdocName
    Control Record
    Data Record
    Segment 3
    Status Record
    Please suggest me step by step process to achieve this task.
    Thanks.

    Thanks a lot Harish for reply.
    I have small doubt. According to your reply , If we have N number of segments in single IDOC with same fields in all segments then for splitting Single IDOC into Multiple IDOC's based on Segment Type we need to duplicate N number of target IDOC tree structure.
    Is that possible to Split single IDOC into Multiple IDOC's based on Segment Type using only one Target IDOC structure without duplicating the Target IDOC structure tree.

  • To select from database table based on date range

    hi
    i have a selection screen in which date range is being given
    say eg 23/06/07  to 23/12/08
    based on this date i want to select data from a ztable
    eg i want to select a field amount from table
    and three is a field date range on the table
    for this particular field i want to select all records for amount field  and factual field falling wiithing this date range and sum it
    eg
    based on date range as in selcetion screen
    select amount( field1)  factual ( field2) from ztable into it_ztable where date = ?....
    please give me code for it  and how to sum all values as i will get from the ztable into internal table the two values as fetched from the ztable
    please suggest asap
    regards
    arora

    hi
    i am using
    sELECT field1 field2 FROM Ztable  INto it_matu
                       where DATE GE sl_dat-low    
                        AND  DATE LE sl_dat-high.   
    i am getting data in internal table but
    say i have twelve records now i want to sum it the both the columns into and use that sum final amount to display
    let me know how to use sume in the intrranal tabl do i need to use control statement
    how to use the sum for two columns and take into a serperate variable to display
    regards
    aRora

  • Splitting  single row to multiple query result

    Hi All,
    I have a column is a table with data seperated by new like . I need to write a select query which can split this to multiple rows .. can any one help me out .
    please see the xample
    select data_comm from customer where rownum=1
    data_comm
    serial=0
    parallel=1
    comm=1
    a single row contain a field called data_comm which has got data stored seperated by new_line
    I need to write a query which can split data on data_comm and give as multiple rows.
    Thanks in advance

    I think something like this would do the trick.
    Part 1:
    select substr(data_comm, 1, instr(data_comm,chr(10),1)) from customer ;
    Part 2:
    select substr(data_comm,instr(data_comm,chr(10),1)+1,instr(data_comm,chr(10),2)) from customer ;
    Part 3:
    select substr(data_comm,instr(data_comm,chr(10),2)+1,instr(data_comm,chr(10),3)) from customer ;
    Maybe the chr(10) is not the used newline char, but you can figure that one out yourself

  • Split single row into multiple rows containing time periods

    Hi,
    I have a table with rows like this:
    id, intime, outtime
    1, 2010-01-01 00:10, 2010-01-3 20:00
    I would like to split this row into multiple rows, 1 for each 24hr period in the record.
    i.e. The above should translate into:
    id, starttime, endtime, period
    1, 2010-01-01 00:10, 2010-01-02 00:10, 1
    1, 2010-01-02 00:10, 2010-01-03 00:10, 2
    1, 2010-01-03 00:10, 2010-01-03 20:00, 3
    The first starttime should be the intime and the last endtime should be the outtime.
    Is there a way to do this without hard-coding the 24hr periods?
    Thanks,
    Dan Scott
    http://danieljamesscott.org

    Thanks for all the feedback, Dan.
    It appears that the respective solutions provided will give you: a) different resultsets and b) different performance.
    Regarding your 'truly desired resultset' you haven't answered all questions from my previous post (there are differences in the provided examples), but anyway:
    I found that using CEIL or ROUND makes quite a difference, using my 'simple 3 record testset' (30 records vs. 66 records got initially returned, that's less than half of the original). That's quite a difference. However, I must call it a day (since it's almost midnight) for now, so there's room for more optimizement and I haven't thoroughly tested.
    But this might hopefully make a difference performancewise when compared to my previous 'dreaded example':
    SQL> drop table t;
    Table dropped.
    SQL> create table  t as
      2  select 1 id, to_date('2010-01-01 00:10', 'yyyy-mm-dd hh24:mi') intime, to_date('2010-01-03 20:00', 'yyyy-mm-dd hh24:mi') outtime from dual union all
      3  select 2 id, to_date('2010-02-01 00:10', 'yyyy-mm-dd hh24:mi') intime, to_date('2010-02-05 20:00', 'yyyy-mm-dd hh24:mi') outtime from dual union all
      4  select 3 id, to_date('2010-03-01 00:10', 'yyyy-mm-dd hh24:mi') intime, to_date('2010-03-03 00:10', 'yyyy-mm-dd hh24:mi') outtime from dual;
    Table created.
    SQL> select id
      2  ,      max(intime)+level-1 starttime
      3  ,      case
      4           when level = to_char(max(t.outtime), 'dd')
      5           then max(t.outtime)
      6           else max(t.intime)+level
      7         end outtime
      8  ,      level period      
      9  from   t
    10  connect by level <= round(outtime-intime)
    11  group by id, level
    12  order by 1,2;
            ID STARTTIME           OUTTIME                 PERIOD
             1 01-01-2010 00:10:00 02-01-2010 00:10:00          1
             1 02-01-2010 00:10:00 03-01-2010 00:10:00          2
             1 03-01-2010 00:10:00 03-01-2010 20:00:00          3
             2 01-02-2010 00:10:00 02-02-2010 00:10:00          1
             2 02-02-2010 00:10:00 03-02-2010 00:10:00          2
             2 03-02-2010 00:10:00 04-02-2010 00:10:00          3
             2 04-02-2010 00:10:00 05-02-2010 00:10:00          4
             2 05-02-2010 00:10:00 05-02-2010 20:00:00          5
             3 01-03-2010 00:10:00 02-03-2010 00:10:00          1
             3 02-03-2010 00:10:00 03-03-2010 00:10:00          2
    10 rows selected.
    SQL> By the way: I'm assuming you're on 10g, is that correct?
    Can you give us some information regarding the indexes present on your table?

  • Splitting the single record into multiple records based on validity

    Hi Guru's,
    basically i am an BI consultant with less knowledge on ABAP, can i request your help on the ABAP task.
    I am working on HR module which is integrated with SAP BI,  the reports will be executed based on calendar month the requirement is i should split the single record into a multiple records based on validity of the record.  basically the HR data would be in data from and date to. 
    below is the logic
    Check whether the start and end date of the record are in the same month and year.
    If yes  nothing changes
    If no  create multiple records
    1st record  original start date of the record u2018till end of that month
    Following record  1st of the next month  u2018till last day of the month
    u2026
    Last record  1st of the month u2018till original end date.
    All fields will have the same values, only the datefrom and dateto fields change.
    Can any one please provide me the same code to proceed on my task.
    Thanks and Regards,
    Venkat

    Hi,
    Using Rule group we can split it.
    Using Rule Group in SAP-BI  Part - 1
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/business-intelligence/s-u/using%20rule%20group%20in%20sap-bi%20%20part%20-%201.pdf
    Thanks
    Reddy

  • How to Split 1 Order into Multiple Deliveries based on Partner Function ?

    Hello,
    How can I split one Sales Order into multiple deliveries, based on the partner function "managed by" ?
    The requirement is that one order will be created for different "managed by".
    If partner function "managed by" is same at line item level in order, than the items having same "managed by" can be combined in one delivery, else delivery will split and multiple deliveries will be created from 1 Order.
    Jatin Mistry

    Hi,
    You need to create a new requirement in tcode VOFM for that, together with your ABAP consultant. This requirement will be used in copy contol.
    http://saptechsolutions.com/pdf/VOFMCopyRequirementRoutines.pdf
    MdZ

  • Splitting single video into multiple files - workflow improvements?

    I regularly need to split a single video into multiple separate files that are used by other programs.  I'm using Premiere Pro CS4 for a number of reasons including the ability to easily and accurately select a scene by individual frames, native audio and video effects/filters, and the ability to import and export various video types.  I'm open to using other tools, but I haven't yet found one that is even close to Premiere Pro when it comes to accurately selecting split points.
    I'm not a Premiere Pro expert.  I have been doing this for about four months and have read many resources (books, forum posts, help guides) to refine the workflow I'm currently using.  My question:  does anyone know any improvements that might save me time/keystrokes.
    Current workflow:
    I've bound F8 to File > Export > Media
    Import video file
    Open in source monitor
    Set In and Out points for scene in source monitor
    Ctrl-drag from source monitor to Project Panel (creates a subclip)
    Repeat 3 and 4 for all scenes/subclips
    Select all subclips from Project Panel and drag to timeline
    Set work area bar to first subclip in timeline by the following four keystrokes:  Home, Alt-[, PageDown, Alt-]
    Type F8 (File > Export > Media shortcut).  Type output file name, click OK and the first subclip is put in the AME queue
    For the remaining subclips, type: Alt-[, PageDown, Alt-], F8, output file name, OK and repeat until done
    Any thoughts/ideas on workflow improvements?
    Thank you!

    Thank you Hunt.
    For the sake of brevity, I didn't include all of the details about the various aspects of the projects.
    Early on I was doing what you suggested and yes, it is a little quicker.  I learned (painfully) a couple of months later that I sometimes have to go back and adjust the clips and this method (trim to timeline with no subclips) resulted in quite a bit of duplicate effort (to reobtain start/stop points).  I've since learned that managing the "scenes" as subclips in topical bins allows me to go back and make adjustments, long after I've totally forgotten about the project content, without a lot of unnecessary reworking.

  • Single row of XML data missing

    OK, much strangeness here.
    I have an mx:DataGrid taking its data from an array
    collection thusly:
    logSheetData = logs.lastResult.logsheet.data as
    ArrayCollection;
    The XML is being generated perfectly by a php page.
    If the xml consists of 2 or more nodes (i.e. the mysql_query
    returned 2 or more rows of data from the database) then the grid
    populates properly and everyone is happy. However, if the query
    returns only a single row of data, the grid is blank.
    I've checked the php and the contents of the database - if
    there's only a single row of data to come back, one row's worth of
    XML is returned.
    This has been driving me mad all morning! Help!
    -Update-
    I have patched the problem by adding in an empty node to the
    xml structure if only 1 row of data is returned - this seems to
    fool the grid and causes it to display properly. Buy why!

    Corvette Captain wrote:
    In an interactive report, is it possible to display the data from one database row over two or more displayed rows on a page?Yes. Create the required structure using the Detail View properties.
    Users can switch between views using the view controls. You can display the report in Detail View by default via a Dynamic Action: +{thread:id=2187972}+

  • Getting correct row based on date

    Hi,
    if i have the following records for an account:
    now i have a date of 4-1-2013 and I want the row where either 4-1-2013 falls withing the BeginDt and EndDt OR if it does not fall within the BeginDt and EndDt, i wann the EndDt = null row.  So i should only get one row back each time, in this case I
    would get the first row back.
    thanks

    Hi,
    You can use BETWEEN statement to find rows where the date is between your date columns and you can use OR to get the second row if it's not inside the interval.
    There are other solutions, I've implemented this one:
    DECLARE @MyTable TABLE (OrgRoleNumTxt VARCHAR(20), BeginDt DATETIME, EndDt DATETIME);
    DECLARE @SearchDate DATETIME;
    INSERT INTO @MyTable
    SELECT '07238', '2013-01-01 00:00:00', '2013-06-30 23:59:59.997'
    UNION
    SELECT '07238', '2015-03-05 00:00:00', NULL
    -- Scenario #1: Returns the first record (between dates)
    SET @SearchDate = '2013-04-01';
    SELECT TOP 1 * FROM @MyTable WHERE (@SearchDate BETWEEN BeginDt AND EndDt) OR EndDt IS NULL ORDER BY BeginDt ASC;
    -- Scenario #2 (same query): Returns the second record (end date is null)
    SET @SearchDate = '2014-01-01';
    SELECT TOP 1 * FROM @MyTable WHERE (@SearchDate BETWEEN BeginDt AND EndDt) OR EndDt IS NULL ORDER BY BeginDt ASC;
    Hope this helps,
    Please use Mark as Answer if my post solved your problem and use Vote As Helpful if a post was useful.
    Pedro Martins
    Portugal
    https://www.linkedin.com/in/rechousa

  • User-filtered report based on date range

    I am struggling with trying to implement a basic search that includes an optional date range for the data. The form looks the way I want it, but I can't seem to get the right syntax in the query. I can't get anything other than "no rows" to show up in the query if I implement a clause selecting records based on the time.
    Here is a working query (without the time):
    select m.AUDIT_ID, m.TIMESTAMP, m.LOC_ID, a.AREA, s.SUBAREA, d.OBSERVATIONS
    from transys.SAFETY_AUDIT_MAIN m, transys.SAFETY_AUDIT_DETAIL d,
    transys.SAFETY_AUDIT_AREA a, transys.SAFETY_AUDIT_SUBAREA s
    where m.AUDIT_ID = d.AUDIT_ID (+)
    and d.AREA_ID = a.AREA_ID
    and d.SUBAREA_ID = s.SUBAREA_ID
    and s.SUBAREA_ID NOT IN (198,199,398,399,498,499,798,799,898,899,999)
    and (instr(upper(a.AREA),upper(nvl(:P210_SEARCH,AREA))) > 0
    or instr(upper(s.SUBAREA),upper(nvl(:P210_SEARCH,SUBAREA))) > 0
    or instr(upper(d.OBSERVATIONS),upper(nvl(:P210_SEARCH,OBSERVATIONS))) > 0)
    I want to compare the m.TIMESTAMP column with page items P210_FROM_DATE and P210_TO_DATE.
    I would also like to add in an optional filter comparing m.LOC_ID to P210_LOCATION, and I can't seem to figure out the "optional" part.
    Any ideas would be helpful.

    The query as I posted it returns 3 values, but it is not syntactically identical to the one APEX is using. I would be happy to get 3 rows in APEX because at least that way I would know I have the date formatting correct, and just needed to tweak the logic. When I execute the query in APEX, however, I get either "there is no data to display" or I get a formatting error - "X is not a valid month" - depending on how I use TO_CHAR and TO_DATE to try and synchronize the various date inputs with the field.
    If it is a query issue (which it may be), I am still suspecting that it is something to do with the formatting of the dates involved. Just as in APEX, it could be something simple, but I suspect it is a mismatch in the formatting somewhere.
    Maybe I'll try making a view of the underlying table and experimenting with the date in the view. That should enable me to see if it is the formatting in the query or the formatting in APEX that is causing the problem. Or it could even eliminate formatting as the problem as well.
    PS. I had a similar struggle trying to implement some triggers against this database that used date values. NLS_TIMESTAMP_FORMAT is set to 'YYYY-MM-DD HH24.MI.SS.FF'. I ended up converting every date that I pulled from the database into a known format with TO_CHAR and then converting it back into a date with TO_DATE. It was the only way to be able to compare the date values without getting these same kinds of errors.

Maybe you are looking for

  • Safari 3.0.4 on OS 10.5.1 not crashing but browser windows DISAPPEAR! Help!

    I know there is a thread in the beta forum with a generic title "Safari acting strange" but I figured a more specific thread title might get more attention from those experiencing the same anomalies. Here is my problem: I'm using Safari 3.0.4 that ca

  • Printing page numbers in report

    hi, I want to print the page numbers in report in a format of PAGE 1 OF 10    PAGE 2 OF 10.... can anybody help me in this thanks in advance. neha.

  • Bind variable issue in Package Body

    When I try to compile my package body, I get an error on the variables declared within the procedure. Bind variable not allowed. Any thoughts?

  • Second RAM slot bad?

    Troubling issue with my 24" iMac (late 2008, 3GHz, nVidia 8800). With both RAM slots loaded, it crashes randomly in the first 15 minutes after boot. Sometimes this is a freeze, others the black "You must restart your computer" message. Regardless, af

  • 9.0 now can't complete purchase--error (no#) re time & cookies

    Updated to iTunes 9.0, tried to purchase couple of apps for ipod touch. Get error cannot complete, that I should make sure date on computer is accurate (it IS) and cookies enabled for iTunes, and refers me for more info to a webpage about accounts on