SQL statement to compare dates and return boolean (yes/no)

I am looking for a SQL statement that can compare 2 dates and return a boolean. 1 (yes) if date 1 is => date2-threshold or 0 (No) if date < date2-threshold
Ie
date1=20130603
threshold=2 days
date2=sysdate-threshold
if [ 20130603 > sysdate-$threshold ]
then
return 1
else
return 0
fi
Thanks to all that answer.

Assumming I want to get "date1" from some other table instead of from
dual will this syntax be valid
I was going to invoke another SQLPLUS from my shell script and pass it in
as a variable but if I can do it on one shot it would be better.
In addition, if "no rows" are found for date1 from the below query, would
I need code to handle that
with xx as
    select TO_DATE(last_date','yyyymmdd') date1, from dba_audit_table where ...;
     select TO_DATE('20130603','yyyymmdd') date1, sysdate date2  from dual;
Thanks to all who answer
[/code1]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Compare data and return the different columns

    Good Afternoon,
    I am trying to compare the data in two tables and return only the columns and data where there is a difference.
    I have a compare script which checks every column in the two tables against each other, but as there are 200 columns in the tables it is tricky to see which column has a difference.
    So in my result set if coulum N is the differenct I would only want to return column N from both tables in the result set.
    I hope that this all makes sense?.

    Easiest way is to use tablediff utility for checking difference between tables
    see
    http://www.mssqltips.com/sqlservertip/1073/sql-server-tablediff-command-line-utility/
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Case statement to compare date and then count duration from only one date

    Hi All;
    I need to compare two dates and if date 1 > date 2 then consider date 2 and count its duration of appointments  from date 2
     case when CTE.scheduledstart  between [dbo].[DateTimeConvert] (new_dateofapplication) and 
             [dbo].[DateTimeConvert](ac.new_businessstartdate)
             then
            (CTE.scheduleddurationminutes)
     when  ( [dbo].[DateTimeConvert] (new_dateofapplication) >  [dbo].[DateTimeConvert](ac.new_businessstartdate))
            then
             [dbo].[DateTimeConvert](ac.new_businessstartdate)
            end as 'AFTERAPP',
    Any help on this is much appreciated
    I need to use case statement fro this
    Thanks
    Pradnya07

    when you say list of Appointments from Appointments table calculate duration from this date [dbo].[DateTimeConvert]
    do you mean find out duration from multiple record? or do you want
    suration for each row? also what represents this date here? Is it new_dateofapplication?
    can you show expected result for the data posted above?
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to compare date and time together

    Hi,
    How to compare Date and Time together?
    For example in a database table there are two fields rundate and runtime.  I want to compare these two with perticular date and time in the program.  Like, I want to pull all the records where the records's date and time are less than a perticular date and time in the program.
    Hope the question is clear...
    Thanks.
    Kavita

    Hi Kavita
    There is no as such Date and Time Comparision FM in Standard SAP  But You can define your own like this
    <b>FUNCTION ZAV4_COMPAREDATETIME.
    ""Lokale Schnittstelle:
    *"  IMPORTING
    *"     REFERENCE(DATE1) TYPE  DATS
    *"     REFERENCE(TIME1) TYPE  TIMS
    *"     REFERENCE(DATE2) TYPE  DATS
    *"     REFERENCE(TIME2) TYPE  TIMS
    *"  EXPORTING
    *"     VALUE(TWOISMORETOPICAL) TYPE  C
      twoismoretopical = ''.
      if date2 > date1.
        twoismoretopical = 'X'.
      else.
         if date2 = date1 and time2 > time1.
           twoismoretopical = 'X'.
         endif.
      endif.
    ENDFUNCTION.</b>
    Regards
    Mithlesh

  • Function module for comparing dates and times

    Hi,
    I have a date and time stamp in one filed for example as below:
    20070125183045
    (the first 8 are date in YYYYMMDD format, the next 6 is time in HHMMSS format). Now I want to compare this value to another such value in terms of date and time. First I want to compare dates and then times. Do you know any function module that can serve this purpose?
    Thanks very much!

    You can compare these using the function module DURATION_DETERMINE.  This fuction will give you the difference, and it can be in a view different units, such as the difference in days, months, etc.
    Funciton module takes in Start date and time and end date and time.
    Regards,
    RIch HEilman

  • Need help in using SQL in a jsp file to compare date and time

    hi every one,
    Actually I am doing a project using JSP. I need to compare a date field in the database (MS Acess) to the current system date and time. I have to do this in a select statement.
    I have alredy defined a variable of type Date in the JSP file and I am comparing this variable to the date in the database through a select statemant.
    Here is what I am doing
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
              java.util.Date today = new java.util.Date();
              String myDate=sdf.format(today);
    query = "SELECT Car_ID, Model_ID, Year, Ext_Color, Price from Cars where EDate <= "+myDate+" ;";
    EDate is the feild in the database and it's format is (5/12/2008 5:29:47 PM) it is of type Date/Time in MS Acess.
    when I execute the query it gives the following error
    SQL error:java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'EDate <= 2008-10-16 08:10:07'.
    I hope any one can help me with that error and answer my question, I've tried too many things but nothing helps
    Thanks in advance :-)

    Hi,
    When the comparision is needed to be done with the current date , we don't need to send in Java
    Date then format it and compare with MS Acess Date.
    In MS Access we have Date() function which will give you the current date.
    So you can try rewriting your query as following :
    query = "SELECT Car_ID, Model_ID, Year, Ext_Color, Price from Cars where EDate <= Date() ;"; ---------------------
    Hope this helps.
    Thanks

  • After specifying a DSN, and an sql statement to SELECT data I can run the Complete SQL

    Session VI in the SQL toolkit. The query results return the requested data, and no errors are produced. When I depress the run arrow a second time, I get an illegal operation message and have to shut down Labview. Have you had problems like this before?

    Session VI in the SQL toolkit. The query results return the requested data, and no errors are produced. When I depress the run arrow a second time, I get an illegal operation message and have to shut down Labview. Have you had problems like this before?Hello,
    You may want to see if there is an update for the ODBC driver of the database you are using. Many times, a crash is caused because of a problem with the driver. You may also want to search the NI website for more information (search for +SQL +Sybase for example, if you are using a Sybase database.)
    Good luck!
    Sincerely,
    Darren Nattinger
    Applications Engineer
    National Instruments
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman

  • SQL Where clause when comparing dates and times in ASP

    Hello,
    I am trying to pull data from my database which is dependant on both the date and time in HH24 format. So, my where clause looks something like this:
    select * from thisTable where activity_time >= myCurrentDate
    (myCurrentDate is a variable that is built which gives it the following format DD-MON-YYYY HH24:MI:SS)
    So, the actual passed string to my call is:
    select * from thisTable where ACTIVITY_TIME >= '02-DEC-2008 18:22:00' order by ACTIVITY_TIME asc
    However, when calling this, I get the famous "ORA-01830: date format picture ends before converting entire input string"
    Can anyone please help me?!?!?!?
    Thanks in advance

    Enrique answered your immediate question, but I'd like to point up a broader issue, and that is that you should <b><u>always</u></b> use the TO_DATE and TO_CHAR functions at the sql statement level when working with date datatypes. That way you are never dependent on some default over which you have no control. I call that is 'defensive coding'.

  • Compare Dates and select the max date ?

    Hello,
    I am trying to write a script and will compare the dates in " eff_startdt" and give me the lastest date at the outcome.
    I have data that some service locations have more than one contract date and I need to get the latest dated conract dates to work on the data but I tried many things I am always getting errors. When I run the script below I get " missing expression" error. I dont' see anything missing.
    also somehow Max() is keep giving me errors when I do something like [  ON service_locs = vmeterid WHERE SERVICE_LOCS = SERVICE_LOCS AND EFF_STARTDT = MAX(EFF_STARTDT)  ]
    Can someone pls give me advice on this. Thanks
    SELECT DISTINCT Broker, customer_name, service_locs, fee_kwh, qtr_monthly, eff_startdt, eff_enddt
    FROM VMETER
    INNER JOIN BROKER_DATA
    ON service_locs = vmeterid WHERE SERVICE_LOCS = SERVICE_LOCS AND (SELECT MAX(EFF_STARTDT) FROM VMETER)
    -----------------------------------------------------------

    Hi,
    I will try to explain on my example. I have got a table:
    DESC SOLD_ITEMS;
    Name                                    Value NULL? Type
    COMPONENT                                          VARCHAR2(255)
    SUBCOMPONENT                                       VARCHAR2(255)
    YEAR                                               NUMBER(4)
    MONTH                                              NUMBER(2)
    DAY                                                NUMBER(2)
    DEFECTS                                            NUMBER(10)
    DESCRIPTION                                        VARCHAR2(200)
    SALE_DATE                                          DATE
    COMP_ID                                            NUMBERI have insert example data into my table:
    select component, subcomponent, sale_date,comp_id
      2  from sold_items;
    COMPONENT       SUBCOMPONENT    SALE_DAT    COMP_ID                            
    graph           bar             06/04/03          1                            
    graph           bar             06/04/01          2                            
    search          user search     06/04/02          3                            
    search          user search     06/04/01          4                            
    search          product search  06/03/20          5                            
    search          product search  06/03/16          6                            
    graph           bar             06/05/01          7                            
    graph           bar             06/05/02          8                            
    graph           bar             06/05/02          9
    As you can see there are a few components and subcomponents duplicated with different date and comp_id value.
    I want to get component and subcomponent combination with latest date.
    SELECT COMPONENT, SUBCOMPONENT, MAX(SALE_DATE)
      2  FROM SOLD_ITEMS
      3* GROUP BY COMPONENT, SUBCOMPONENT;
    Efect:
    COMPONENT       SUBCOMPONENT    MAX(SALE                                       
    graph           bar             06/05/02                                       
    search          user search     06/04/02                                       
    search          product search  06/03/20
    For your purpose I will do it using join and subquery. Maybe it will help you resolve your problem:
    SELECT COMPONENT, SUBCOMPONENT, SALE_DATE, RANK
      2  FROM (SELECT T1.COMPONENT, T1.SUBCOMPONENT, T2.SALE_DATE,
      3          ROW_NUMBER() OVER (PARTITION BY T1.COMPONENT, T2.SUBCOMPONENT ORDER BY T2.SALE_DATE DESC) AS ROW
      4          FROM SOLD_ITEMS T1, SOLD_ITEMS T2
      5          WHERE T1.COMP_ID = T2.COMP_ID)
      6* WHERE ROW = 1;
    I joined the same table but it act as two different tables inside subquery. It will group values (partition by statement) and order result descending using t2.sale_date column. As you can see columns are returned from both tables. If you would like to add some conditions, you can do it after WHERE ROW=1 code.
    Results:
    COMPONENT       SUBCOMPONENT    SALE_DAT       RANK                            
    graph           bar             06/05/02          1                            
    search          product search  06/03/20          1                            
    search          user search     06/04/02          1Hope this help you
    Peter D.

  • Need a sql statement to remove data?

    Hello,
    I need your help regarding my query.
    I need to put a sql statement in a shell script that will delete records from a table that is > than 3 months old and if not, do nothing.
    The table has a DATE column as shown below:
    LOG_ID NOT NULL VARCHAR2(8)
    LOG_TYPE NOT NULL VARCHAR2(8)
    LOG_MESSAGE NOT NULL VARCHAR2(255)
    LOG_DATE DATE
    I'm a novoice at sql and request you to provide me a sql statement that will do the above.
    Much appreciated!
    Regards,

    SQL> select sysdate from dual;
    SYSDATE
    14-JUL-09
    SQL> select add_months(sysdate,-3) from dual;
    ADD_MONTH
    14-APR-09
    SQL> select add_months(sysdate,-3)-1 from dual;
    ADD_MONTH
    13-APR-09
    DELETE FROM {table_name} WHERE HIREDATE<={pick the date format from above accordingly}

  • Show SQL issue on Posting Date and Aging Date

    Hi Folks,
    When I am running a report >>> the report pops up with the some parmeters >>
    In my scenario u201CAging Dateu201D forumla is calculated as the last day of the every month.
    if month (currentdate) = 1 then date((year(CurrentDate)-1),12,31) else
    date(year(currentdate),month(CurrentDate),1)-1
    Example : if 9( 23 sep 2010 ) = 1 then date ((2010(23 Sep 2010)-1),12,31) else date(2010(23 sep 2010),9( 23 Sep 2010),1)-1.
    Issues :
    For some reports the Aging Date parameter is poping up but for some of the reports the Aging Date forumla is calculating in the behind based on the u201CPost Dateu201D.
    Here is my Record Selection :
    (not isnull({CLARITY_TDL.SERV_AREA_ID}) and {CLARITY_TDL.SERV_AREA_ID}
    in {?Service Area} or 0 in {?Service Area}) and
    (not isnull({CLARITY_DEP.SPECIALTY}) and {CLARITY_DEP.SPECIALTY} in {?Specialty} or {?Specialty} =
    "Specialty(s)" or {?Specialty} = "NONE") and
    (not isnull({CLARITY_TDL.PERFORMING_PROV_ID}) and {CLARITY_TDL.PERFORMING_PROV_ID} in {?Service Provider} or
    {?Service Provider} = "Provider(s)" or {?Service Provider} = "NONE") and
    {CLARITY_TDL.POST_DATE} = {@Aging Date}and
    [color=darkred]{CLARITY_TDL.DETAIL_TYPE} in [60, 61] and
    {CL_EMP_CLARITY.USER_ID} = CurrentCEUserName
    Moreover when I check Show SQL for the where clause
    CLARITY_TDL"."SERV_AREA_ID" IS NOT NULL AND "CLARITY_TDL"."SERV_AREA_ID"=10 AND "CLARITY_TDL"."POST_DATE">={ts '2010-08-31 00:00:00'} AND "CLARITY_TDL"."POST_DATE"<{ts '2010-09-01 00:00:00'})
    AND ("CLARITY_TDL"."DETAIL_TYPE"=60 OR "CLARITY_TDL"."DETAIL_TYPE"=61) AND "CL_EMP_CLARITY"."USER_ID"=''
    I donu2019t know why the post date is going in between the date/time ranges. I am scrating my head to understand the things to work. Please help me out.

    Not sure what you are trying to do here
    (not isnull({CLARITY_TDL.SERV_AREA_ID}) and {CLARITY_TDL.SERV_AREA_ID}
    in {?Service Area} or 0 in {?Service Area}) and
    (not isnull({CLARITY_DEP.SPECIALTY}) and {CLARITY_DEP.SPECIALTY} in {?Specialty} or {?Specialty} =
    "Specialty(s)" or {?Specialty} = "NONE") and
    (not isnull({CLARITY_TDL.PERFORMING_PROV_ID}) and {CLARITY_TDL.PERFORMING_PROV_ID} in {?Service Provider} or
    {?Service Provider} = "Provider(s)" or {?Service Provider} = "NONE") and
    Probably better to right these on these lines
    (If {?Service Area} not equals 0 then not isnull({CLARITY_TDL.SERV_AREA_ID}) and {CLARITY_TDL.SERV_AREA_ID}
    in {?Service Area}  else true) and
    NB Typed not equals as symbols disappear
    This means nothing in SQL and will cause whole clause to be evaluated locally and not on database
    or {?Specialty} =
    "Specialty(s)" or {?Specialty} = "NONE")
    I am not sure what you are trying to do so can not offer an alternative.
    Ian

  • Call external URL from ABAP userexit, capture data and return it to SAP?

    My apologies if this question has been asked before, but I've searched for a few hours today and haven't found anything directly related to my question.  Thank you in advance for any help you may be able to provide!
    I would like to be able to make a call from an SAP userexit during Sales Order Entry in the VA01 transaction in the SD module to an external website, allow the user to capture some data in the external site and then pass that data back into the userexit where I can use it to populate internal tables, etc.
    I'm completely unfamiliar with Web Dynpro programming, but this seems like a good place to start my search for a solution. 
    Does this sound like a problem that can be solved with Web Dynpro and what documentation or code examples should I reference to go about building such a solution.
    I should also note that I'm hoping to build a solution that could be called from any userexit in R/3, SAP ERP, SAP CRM, etc. and would obviously need to learn about what dependencies to consider (ex: SAP GUI version, SAP product release number, Web AS release, etc.).
    Eric

    Thank you for the response.  Let me provide some additional information.
    The external application will be a Hosted Web page.  It is not an SAP system. 
    The external application will be a web page served by a separate system outside of the company domain(shouldn't matter what the technology is I would think - but the web page will be hosted by a different company than the one calling the URL) that would appear as a web page in which the user will enter data, logic will be performed on that data and then some or all of the data would need to be passed back to the calling point in SAP.
    For practical discussions it doesn't matter to me if the call in ABAP occurs in an SD userexit, in a custom report, in an HR screen or in a CRM business partner screen.  There will be many places where this external application may be called from and I'm just trying to figure out how to call an external HTTPS URL and return data from that web page to the calling point in ABAP.
    I hope that clarifies my question.
    Thanks!
    Eric

  • Formula for comparing dates and display data

    I have 3 objects on my query: Date, Product name and Quantity sold
    I have a table on my reports showing the top 3 products by quantity sold, and I want to add the quantity sold today on the same table.
    I am looking for a formula that compares de dates provided by the query with current date and only displays on the cell the quantity for the current day.
    Any ideas are welcome!

    As per my understanding, you want to display the today's sale of the product while the ranking is aaplied on the total quantity
    sold.
    You can create a new variable with either of the following two definitions:
    Today's Date = CurrentDate()
    Today's Sale = Sum([Quantity Sold]) where ([Date]=[Today's Date])
    or
    Today's Sale = If(([Date]=[Today's Date]) Then Sum([Quantity Sold])
    Note: The two date formats should be same.
    For getting the top three products you can use the hidden column(font, border and background white) and apply the ranking on
    the total sale coming from the DB.
    Regards,
    Rohit

  • SQL statement - when no data found

    I have this SQL statement as follows:
    SELECT (Case When tar_customer_id <> 0 Then tar_customer_id Else 0 End) INTO l_balance_customerID FROM sh_ba_balance WHERE tar_customer_id = p.customer_id;    However, when I tried run it, I have this error:
    ORA-01403: no data foundHow do set l_balance_customerID as 0 when no data is found?

    [url http://forums.oracle.com/forums/thread.jspa?messageID=2754839&#2754839]duplicate thread

  • In SQL server, how can I pass a date and return on any specific day of the week (e.g. Sunday/Monday/Wednesday, etc.)

    In SQL server, I want to be able to have a function to return the date of any specific day of the week by passing two parameters. E.g.:
    parameter 1: a selected date (e.g. 8/3/2013)
    parameter 2: any specific day of the week (e.g. Wednesday)
    result: should be 7/31/2013 (8/3/2013 is a Sunday in the week 7/28 - 8/3, so the Wednesday should be 7/31/2013)
    then if I want to get Saturday of that week, I can simply change the second parameter to 'Saturday'
    Thanks.

    Wrong forum:
    http://www.microsoft.com

Maybe you are looking for

  • Videos no longer playback after upgrade to itunes 7

    Yesterday I upgraded to itunes V.7. Now none of my videos or video podcasts play. I Also upgraded my Ipod and none of the videos show up. The error messege when connecting my ipod is as follows "The video format is not supported on this ipod" All my

  • Display telugu word in a jsp

    Hi, i have an assignment please help me in doing that. how to display a telugu word in a jsp page. can u please please help me .......... waiting for the reply thanks in advance

  • Dynamic color selection

    Hi Is is possiable to display the color palatte of developer during run time so that the user can chose the color for some fields based on his choice. null

  • Apex 3.2 Spell Check Bug?

    I have a text area with spell check that holds 4000 characters. The spell check works well until approx 3800 characters are entered into the field. At that point in time the spell check brings up a page can't be displayed popup. Ideas?

  • NullPointerException when filling in stacktrace?

    Hi, In the app I'm trying to understand, an exception is thrown. I know so, as I use log4j to log what happens. Log4j is set to DEBUG. This is some of my code public class CreateCustomerAction extends Action {   //Logger   static Logger logger = Logg