+ Reply to Thread
Results 1 to 5 of 5

How refer to current date in Excel SQL query?

  1. #1
    Ronald S. Cook
    Guest

    How refer to current date in Excel SQL query?

    I'm trying to use Microsoft Query within Excel to write a SQL query against
    a data set.

    SELECT e.EVENTNAME, e.EVENTDATE
    FROM EVENT e
    WHERE (e.EVENTDATE >= DATE()
    ORDER BY e.EVENTDATE

    In the above, DATE() is not correct to get the current system date. I tried
    DATE, NOW, NOW(), GETDATE, GETDATE(), TODAY, TODAY().. now of which worked.

    Can someoine please tell me the correct syntax?

    Thanks!
    Ron



  2. #2

    Re: How refer to current date in Excel SQL query?

    Ronald, Here is the way I handle the Date issue..

    strToday = DateValue(Now())

    SQL = Select * from MyTable where DateField < strToday



    Ronald S. Cook wrote:
    > I'm trying to use Microsoft Query within Excel to write a SQL query against
    > a data set.
    >
    > SELECT e.EVENTNAME, e.EVENTDATE
    > FROM EVENT e
    > WHERE (e.EVENTDATE >= DATE()
    > ORDER BY e.EVENTDATE
    >
    > In the above, DATE() is not correct to get the current system date. I tried
    > DATE, NOW, NOW(), GETDATE, GETDATE(), TODAY, TODAY().. now of which worked.
    >
    > Can someoine please tell me the correct syntax?
    >
    > Thanks!
    > Ron



  3. #3
    Ronald S. Cook
    Guest

    Re: How refer to current date in Excel SQL query?

    But what I'm writing is write in the SQL query window so I can't establish
    variables, etc.

    I tried the below but it didn't work either:

    >> SELECT e.EVENTNAME, e.EVENTDATE
    >> FROM EVENT e
    >> WHERE (e.EVENTDATE >= DateValue(Now())
    >> ORDER BY e.EVENTDATE



    <[email protected]> wrote in message
    news:[email protected]...
    > Ronald, Here is the way I handle the Date issue..
    >
    > strToday = DateValue(Now())
    >
    > SQL = Select * from MyTable where DateField < strToday
    >
    >
    >
    > Ronald S. Cook wrote:
    >> I'm trying to use Microsoft Query within Excel to write a SQL query
    >> against
    >> a data set.
    >>
    >> SELECT e.EVENTNAME, e.EVENTDATE
    >> FROM EVENT e
    >> WHERE (e.EVENTDATE >= DATE()
    >> ORDER BY e.EVENTDATE
    >>
    >> In the above, DATE() is not correct to get the current system date. I
    >> tried
    >> DATE, NOW, NOW(), GETDATE, GETDATE(), TODAY, TODAY().. now of which
    >> worked.
    >>
    >> Can someoine please tell me the correct syntax?
    >>
    >> Thanks!
    >> Ron

    >




  4. #4
    Ronald S. Cook
    Guest

    Re: How refer to current date in Excel SQL query?

    But what I'm writing is write in the SQL query window so I can't establish
    variables, etc.

    I tried the below but it didn't work either:

    >> SELECT e.EVENTNAME, e.EVENTDATE
    >> FROM EVENT e
    >> WHERE (e.EVENTDATE >= DateValue(Now())
    >> ORDER BY e.EVENTDATE



    <[email protected]> wrote in message
    news:[email protected]...
    > Ronald, Here is the way I handle the Date issue..
    >
    > strToday = DateValue(Now())
    >
    > SQL = Select * from MyTable where DateField < strToday
    >
    >
    >
    > Ronald S. Cook wrote:
    >> I'm trying to use Microsoft Query within Excel to write a SQL query
    >> against
    >> a data set.
    >>
    >> SELECT e.EVENTNAME, e.EVENTDATE
    >> FROM EVENT e
    >> WHERE (e.EVENTDATE >= DATE()
    >> ORDER BY e.EVENTDATE
    >>
    >> In the above, DATE() is not correct to get the current system date. I
    >> tried
    >> DATE, NOW, NOW(), GETDATE, GETDATE(), TODAY, TODAY().. now of which
    >> worked.
    >>
    >> Can someoine please tell me the correct syntax?
    >>
    >> Thanks!
    >> Ron

    >




  5. #5

    Re: How refer to current date in Excel SQL query?

    May just be the position/use of your parenthesis.. I tried the
    following clause in MS Access and then in the MS Query window and both
    gave me the same result..

    WHERE ((TblTraffic.RPT_DATE)<Now())

    HTH,
    Will


    Ronald S. Cook wrote:
    > But what I'm writing is write in the SQL query window so I can't establish
    > variables, etc.
    >
    > I tried the below but it didn't work either:
    >
    > >> SELECT e.EVENTNAME, e.EVENTDATE
    > >> FROM EVENT e
    > >> WHERE (e.EVENTDATE >= DateValue(Now())
    > >> ORDER BY e.EVENTDATE

    >
    >
    > <[email protected]> wrote in message
    > news:[email protected]...
    > > Ronald, Here is the way I handle the Date issue..
    > >
    > > strToday = DateValue(Now())
    > >
    > > SQL = Select * from MyTable where DateField < strToday
    > >
    > >
    > >
    > > Ronald S. Cook wrote:
    > >> I'm trying to use Microsoft Query within Excel to write a SQL query
    > >> against
    > >> a data set.
    > >>
    > >> SELECT e.EVENTNAME, e.EVENTDATE
    > >> FROM EVENT e
    > >> WHERE (e.EVENTDATE >= DATE()
    > >> ORDER BY e.EVENTDATE
    > >>
    > >> In the above, DATE() is not correct to get the current system date. I
    > >> tried
    > >> DATE, NOW, NOW(), GETDATE, GETDATE(), TODAY, TODAY().. now of which
    > >> worked.
    > >>
    > >> Can someoine please tell me the correct syntax?
    > >>
    > >> Thanks!
    > >> Ron

    > >



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1