Date BETWEEN query with a difference?

Hi,
I have a BETWEEN query (at least I think that's what it will need), but with a difference.
Normally you would specific a field which was BETWEEN two set variables
ie. {fieldname} BETWEEN 1 AND 3
However I need mine the other way round.
I have a series of records which have a startdate and enddate held against them.
When a user submits a new record to the db, I need it to check that the starting and ending date range doesn't overlap any of the existing start-end date ranges that exist.
In order to do that I'm trying to build a query which takes in the incoming startdate variable and see if that is within any of the existing start-date-enddate dates ranges of the existing records, and then same for the incoming endate. I actually want the ones that are going to cause a problem to appear...
I;m sure there is a pretty easy way of coding this, but I'm struggling to get my head round it.
 Anyone offer any advice?

You can try something like this
use adventureworks
go
select birthdate from humanresources.employeetest where birthdate between
(select min(birthdate) from humanresources.employee) and
(select max(birthdate) from humanresources.employee)

Similar Messages

  • Dates Between Query :( with out TO_DATE.

    Greetings,
    I have a query whete in the where clause I compare a column b/w two dates. The Query looks like this,
    trunc(LAST_UPDATE_DATE) BETWEEN '22-FEB-03' AND '21-MAR-03'.
    This query doesn't fetch any records. Whereas when I use the query with a TO_DATE function it works fine. The query looks like,
    TRUNC(LAST_UPDATE_DATE) BETWEEN TO_DATE('22-FEB-03','DD-MON-YY') AND TO_DATE('21-MAR-03','DD-MON-YY')
    Ideally I can't impose this becasue the query is a generarted query by one of the reporting tools.
    Kindly Help. I really appreciated your help in this regard.
    Thanks,
    Badhri ...

    Your NLS_DATE_FORMAT is set to something other than 'DD-MON-YY'. This can be changed at a session level by executing a query
    ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YY'
    You could also change this at an instance level, but that would likely have side-effects on other queries. One of the reasons that not having to_date can be a royal pain.
    Justin

  • Date between Query

    how to write a date query between two dates

    or
      select *
        from emp
       where trunc(hiredate) >= trunc(from_date)
         and trunc(hiredate) <= trunc(to_date)

  • Web Template with multiple Data Provider Query with partial authority

    Dear Guru,
    I have a single web template, that contains 2 query data providers (e.g. Query A, Query B), and all users access to this web template for both queries.
    Now, there are some users that have authority to Query A only.
    When they access to this web template, the system automatically say the users do not have authority for Query B in the variable entry screen, and show the variable selection for query A only.
    And the problem comes, when user submit the variable entries, the system keep asking for the mandatory variables for query B, which the user actually not authorized to execute. How can this be fixed??
    Please kindly help me. Thank You.
    Best regards,
    Chris

    Hi all,
    I am looking into the use of Javascript and CustomExtension, but still cannot find any solution.
    Can I use CustomExtension to generate Javascript to redirect the page to another web template??
    Can I use Javascript to check authority of the users, and alter the Web Items?
    Can Anybody help? Many many thanks.
    Best regards,
    Chris

  • Transferring Data between Databases with Character Sets UTF08 and US7ASCII

    Hi,
    I am trying to transfer data from Oracle 10g (character set :UTF08) to Oracle 8i ( character set: US7ASCII). I have tried the transfer using the DBLinks and found that there is no way the data could be transferred from 10g to Oracle 8i.
    The last option available is to use staging database for transfer. The staging database would be Oracle 10g only but the character set would be US7ASCII. I am expecting that since the character set is US7ASCII, this would be able to get compatible with Oracle 8i (US7ASCII). Secondly, Transfer from 10g to staging 10g should also work, since staging 10g would support UTF08 character set.
    Kindly tell me if this option would work or if there is any other way around.
    Thanks
    Nitin
    Message was edited by:
    Nits
    Message was edited by:
    Nits
    Message was edited by:
    Nits

    You possibly have a fundamental problem,which is more important than any technical issues. If your UTF8 (Unicode) database stores non-english characters you will lose these characters when transferring.
    Werner

  • Move data between tables with INSERT-LOOP?

    Greetings
    I need to move all the contact information (contained in 5
    fields- call it the address table) into the table (call it the main
    table) that contains all the other associated information. Tables
    are related via the "vendor_ID" key field.
    There are about 7000 records.
    I tried the attached code- with no luck- am I in the
    ballpark?
    Thanks!
    newportri

    Sorry- yes the tables are in the same DB because I imported
    them together.
    I am trying to clean this DB up for eventual porting to SQL
    Server (it is in Access now) - I saw no good reason why the
    designer used 2 separate tables- one with most info on each vendor,
    but split the addresses off in another table?
    I guess there are lumpers and splitters- but I can't see the
    point of inserting/updating/deleting form 2 tables vs 1?
    ERROR: The field 'Vendor1.vendor_ID' cannot contain a Null
    value because the Required property for this field is set to True.
    Enter a value in this field.
    Thanks for your quick response.

  • Synching calendar dates between 2 handhelds

    Computer idiot here.  Sorry if this is a dumb question.  My wife and I each have a Zire 72.  We want to get the calendars on each of them to show the same appointments etc.  We've tried synching them thru the desktop (we have separate user names on the desktop) but that doesn't seem to work.  Have also tried to beam but the handheld says calendar data can't be beamed.  EIther way, we can't seem to make it happen, but I have to think that there must be a way to do this!  Can anyone tell me how it can be done?  Thanx!
    Post relates to: Zire 72

    You should be able to beam the data, sounds like you are trying to beam the calendar database file thats why its saying it can't do this, instead go into the calendar application then select menu and select send event.
    There is also a program called SyncUs this will allow you to share pim data between devices with each device having its own username.
    Post relates to: Centro (Sprint)

  • Difference between initialization with data transfer?

    Dear Ones,
    What is the Difference between initialization with data transfer,initialization without data transfer and early delta initialization?
    Please explain me in senario basis..
    Thanks
    Shiva

    Hello Shivananda,
    See oss note 505700 :
    The early delta initialization is used to admit document postings
                in the OLTP system as early as possible during the initialization
                procedure.
    Regards,
    Fred

  • Issue with SQL Query with Presentation Variable as Data Source in BI Publisher

    Hello All
    I have an issue with creating BIP report based on OBIEE reports which is done using direct SQL. There is this one report in OBIEE dashboard, which is written using direct SQL. To create the pixel perfect version of this report, I am creating BIP data model using SQL Query as data source. The physical query that is used to create OBIEE report has several presentation variables in its where clause.
    select TILE4,max(APPTS), 'Top Count' from
    SELECT c5 as division,nvl(DECODE (C2,0,0,(c1/c2)*100),0) AS APPTS,NTILE (4) OVER ( ORDER BY nvl(DECODE (C2,0,0,(c1/c2)*100),0))  AS TILE4,
    c4 as dept,c6 as month FROM 
    select sum(case  when T6736.TYPE = 'ATM' then T7608.COUNT end ) as c1,
         sum(case  when T6736.TYPE in ('Call Center', 'LSM') then T7608.CONFIRMED_COUNT end ) as c2,
         T802.NAME_LEVEL_6 as c3,
         T802.NAME_LEVEL_1 as c4,
         T6172.CALENDARMONTHNAMEANDYEAR as c5,
         T6172.CALENDARMONTHNUMBERINYEAR as c6,
         T802.DEPT_CODE as c7
    from
         DW_date_DIM T6736 /* z_dim_date */ ,
         DW_MONTH_DIM T6172 /* z_dim_month */ ,
         DW_GEOS_DIM T802 /* z_dim_dept_geo_hierarchy */ ,
         DW_Count_MONTH_AGG T7608 /* z_fact_Count_month_agg */
    where  ( T802.DEpt_CODE = T7608.DEPT_CODE and T802.NAME_LEVEL_1 =  '@{PV_D}{RSD}' 
    and T802.CALENDARMONTHNAMEANDYEAR = 'July 2013'
    and T6172.MONTH_KEY = T7608.MONTH_KEY and T6736.DATE_KEY = T7608.DATE_KEY
    and (T6172.CALENDARMONTHNUMBERINYEAR between substr('@{Month_Start}',0,6)  and substr('@{Month_END}',8,13))
    and (T6736.TYPE in ('Call Center', 'LSM')) )
    group by T802.DEPT_CODE, T802.NAME_LEVEL_6, T802.NAME_LEVEL_1, T6172.CALENDARMONTHNAMEANDYEAR, T6172.CALENDARMONTHNUMBERINYEAR
    order by c4, c3, c6, c7, c5
    ))where tile4=3 group by tile4
    When I try to view data after creating the data set, I get the following error:
    Failed to load XML
    XML Parsing Error: mismatched tag. Expected: . Location: http://172.20.17.142:9704/xmlpserver/servlet/xdo Line Number 2, Column 580:
    Now when I remove those Presention variables (@{PV1}, @{PV2}) in the query with some hard coded values, it is working fine.
    So I know it is the PV that's causing this error.
    How can I work around it?
    There is no way to create equivalent report without using the direct sql..
    Thanks in advance

    I have found a solution to this problem after some more investigation. PowerQuery does not support to use SQL statement as source for Teradata (possibly same for other sources as well). This is "by design" according to Microsoft. Hence the problem
    is not because different PowerQuery versions as mentioned above. When designing the query in PowerQuery in Excel make sure to use the interface/navigation to create the query/select tables and NOT a SQL statement. The SQL statement as source works fine on
    a client machine but not when scheduling it in Power BI in the cloud. I would like to see that the functionality within PowerQuery and Excel should be the same as in Power BI in the cloud. And at least when there is a difference it would be nice with documentation
    or more descriptive errors.
    //Jonas 

  • What's the exact difference between "Query Def. Filter Value Selection" and

    Hi Gurus,
    what's the exact difference between "Query Def. Filter Value Selection" and "Query Execution Filter Val. Selectn" in info-object's "Business explorer" tab?
    I found out that if my info-object A has a input-ready variable in a query,after the query running,in  the selection screen,my info-object A's F4 value is follow the setting of "Query Execution Filter Val. Selectn",as the setting of "Query Def. Filter Value Selection" I tried every diff setting, it won't effect my query anyway.
    so:
    1.what's the exact difference between "Query Def. Filter Value Selection" and "Query Execution Filter Val. Selectn" in info-object's "Business explorer" tab?
    2.how they effect query's presentation?
    I searched forum,didn't find the answer what I want.
    Thanks everyone.

    Hi Denny,
    I will try to explain it again.
    Query Def. Filter Value Selection : Let say the value is set to "Only Values in Infoprovider"
    Lets take an example infoobject - 0MATERIAL (Material)
    Total material records in material Master = 1000 (master Data table /BI0/PMATERIAL)
    You create a query on top of an Infoprovider using Material.
    Total unique materials in Infoprovider= 500.
    Now when you are in design mode in Query Designer, and you try to restrict Material by few materials (for e.g. 1, 2, and 3), for this you right click on material and select Restrict, the pop-up opens with list of materials, this list is all those 500 materials which are in the infoprovider, because the setting is  "Only Values in Infoprovider". Which means then when you are trying to restrict a characterstic in query definition the list of values displayed for restricition is derived from Infoprovider.
    Query Execution Filter Value Selection  - I think you already know what it is , its the read mode for F4 help selection.
    I hope this helps.
    Thanks
    CK

  • Query with date in where clause

    hi,
    i have build a view with join conditions from 8 tables. the data from this view is more then 100,000
    when i run the query with different clause its work with some seconds. but when i put date column in where cluase it sleeps.
    eg..
    where unit_id = 4 and t_id = 's09' and vb like '%amb%'
    works fine.
    where unit_id = 4 and t_id = 's09' and vb like '%amb%' and date between dt1 and dt2
    now sleep
    please ......give me some suggestions

    hi i have done the explain plan
    the result is
    Operation Object
    SELECT STATEMENT ()
    NESTED LOOPS ()
    NESTED LOOPS ()
    HASH JOIN ()
    HASH JOIN ()
    TABLE ACCESS (FULL) PR_PO_MST
    TABLE ACCESS (FULL) PR_SUPPLIER
    TABLE ACCESS (FULL) PR_PO_DTL
    TABLE ACCESS (BY INDEX ROWID) INDENT_MST
    INDEX (RANGE SCAN) ST_IND_MST_IDX
    TABLE ACCESS (BY INDEX ROWID) ST_ITEM
    Operation Object
    INDEX (UNIQUE SCAN) PK_ST_ITEM
    now wot do do????

  • OWL with Default Set containting Current Date as query parameter

    Hello Everybody,
    I have a custom BO which mainly consists of a name and a time period (start and end date).
    Now I'd like to create a Default set like
    "Give me all objects with today between start and end date."
    I already tried the following:
    Filling a field using UI-Scripting:
    $data.UIState.Today = $controller.DateTimeUtils.DateNow;
    Copy the field into the search parameter
    executing the query with this search parameter.
    However, I using this approach, I only managed to search for objects matching exactly todays date, but not using greater/lower comparators.
    Furthermore I also searched for a field transformation giving me the current date but did not succeed.
    Does anyone have any ideas how to achieve this or how to get one of the above ideas to work?
    Best regards,
    Ludger

    Hello Ludger,
    That`s what I expected: The fields do not define the interval.
    Therefore you need to define it by yourself via this "less or equal".
    What you can do in the UI Designer at the query definition is to provide an interval
    For the field "CurrentDate" provide
    - SelectOption = "between"
    - Low Value = your start date
    - High Value = your end date
    - Select Option = "include"
    HTH,
        Horst

  • Date Query With Restricted Dates

    Sorry not really an easy thing to explain:
    I have specified in a Query that i Only want values with a date BETWEEN:
    01JAN2002 08:00 AND 01SEP2003 08:00
    Now in the same query, what is the simplest way to restrict that only the following dates are examined and not all the dates within the above time window:
    Say 06/01 - 07/01
    The following dates i am looking to analyze will thus be
    01JUN2002 08:00 - 01JUL2002 08:00
    01JUN2003 08:00 - 01JUL2003 08:00
    Thanks

    Had a little bit more time to test, today. So in case you couldn't find the complete soultion yourself, here you go. The records with flag='Y' are the ones that fit within your selection criteria (between any 7-OKT 8:00AM and 8-OKT 8:00AM).
    drop table testDate;
    create table testDate(id number,flag char,yourDate date);
    insert into testDate values (1,'Y',to_date('7-OKT-2003 11:00:00','DD-MON-YYYY HH:MI:SS'));
    insert into testDate values (2,'Y',to_date('8-OKT-2003 7:00:00','DD-MON-YYYY HH:MI:SS'));
    insert into testDate values (3,'N',to_date('7-OKT-2003 3:00:00','DD-MON-YYYY HH:MI:SS'));
    insert into testDate values (4,'N',to_date('8-OKT-2003 11:00:00','DD-MON-YYYY HH:MI:SS'));
    insert into testDate values (5,'Y',to_date('7-OKT-2002 11:00:00','DD-MON-YYYY HH:MI:SS'));
    insert into testDate values (5,'N',to_date('6-OKT-2002 11:00:00','DD-MON-YYYY HH:MI:SS'));
    insert into testDate values (5,'N',to_date('9-OKT-2002 11:00:00','DD-MON-YYYY HH:MI:SS'));
    commit;
    select id,flag,to_char(yourDate,'DD-MON-YYYY HH:MI:SS') from testDate
    where trunc(yourDate,'HH')-trunc(yourDate,'YYYY')
    between to_date('7-OKT-2003 08:00:00','DD-MON-YYYY HH:MI:SS')-to_date('01-JAN-2003')
    and to_date('8-OKT-2003 08:00:00','DD-MON-YYYY HH:MI:SS')-to_date('01-JAN-2003')
    /

  • Query to retrieve Differences in show hstory form in BP Master Data

    Hi ,
    We need to have the query where the differences in show history of BP Master data.
    Please do the needful.
    Thanks
    Vinod Boga
    +91-98496 45825.

    Hi Vinod
    Is not enough using Tools --> History Log ??
    It show a form with a modification history of your BP

  • Sql Query for getting data between two dates

    Dear Sir,
    I have one problem, i have date stored in varchar datatype of (X) table in mysql as it was not supporting the date format of (dd/mm/yyyy) so know the problem is,
    When i going to get the data between the the two dates it is giving the un reliable answers such that
    when i am asking the query as data between 1st April to 31st December 2009 it is showing the data from the 2008 .
    is there any way to solve this problem,please help this is an urgent requirement, your replay will be helpful to me.
    With Regards
    Ramakrishna Y

    You either have a SQL problem and this is the incorrect place to ask.
    Or you have a Java problem in code we cannot see. When posting code use the code tags. Click the CODE button and paste your code between the tags that appear.

Maybe you are looking for

  • Droid Razr M Battery after KitKat Update

    I recently updated my Droid Razr M with the KitKat update when prompted.  Battery life went from not needing to be charged for well over a day, to draining from 100% before the work day ended with light use.  I contacted Verizon and humored them and

  • Why my ipod classic 7th video wont play after 20:46????

    my problem is i put mp4 into the ipod ......and all the video will only play up to 20:46 and it will skip to the next one....and the video will work on my ipad ..no problem at all.....anybody knows why??

  • Please help me(BIOS)

    I updated the bios and while updating it hung .Now is not included in the BIOS, try a combination of win + b but does not help. HP ALL-IN-One ENVY20 D013W. more than that is not loaded on the screenshot.Sorry for my english,use google translate.Pleas

  • Handling successive versions of the same help project in VSS

    If I understand it correctly, RHX5 always gets the most-recent version of a version-controlled project from Visual SourceSafe. Sometimes, however, I may want to build an older, labeled version of the project. By using VSS directly, I think I would be

  • Schedule for Outlook 2011 calendar sync?

    Hi Has anyone seen a schedule for Outlook 2011 to sync calendars with iPhone? If you were thinking of getting the version of Office for MAC that has Outlook 2011 you might want to hold off for while. It seems Microsoft left it that bit out... thanks