Using wild card in DateTime

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Using wild card in DateTime

    Need help on defining a SQL query statement.

    I have a field in my table defined as "Date/Time". This is in Access.

    The data looks like this in the field, "4/19/2004 8:59:17 AM" when entered.

    When I run the sql query statement with date and time like this, works well.
    SELECT * FROM [Florida] WHERE Call_Date = #4/19/2004 8:59:17 AM#

    I want to query the DateTime field by date only and I don't care about the
    time.

    If I run it by this,
    SELECT * FROM [Florida] WHERE Call_Date = #4/19/2004 ??:??:?? AM#

    Error: Syntax error in date in query expression 'Call_Date = #4/19/2004
    ??:??:?? AM#'.

    SQL : SELECT * FROM [Florida] WHERE Call_Date = #4/19/2004 ??:??:?? AM#


    Can you give me any ideas what I am doing wrong?

    Appreciate any help.

    Thanks,
    jt



    jt Guest

  2. Similar Questions and Discussions

    1. Query of Query LIKE and Wild Card chars
      I am tyring to use the 'LIKE' comparison within a Query of Query. The Query is shown below. <cfquery dbtype="query" name="GetFileList"> select...
    2. Passing "%" wild card to stored procedure
      Hi everyone, This may be a simple question: When I pass "%" (without the quotes) in an asp page to a stored procedure, I get the Incorrect...
    3. apt-get source: bash wild card
      Hi, Unlike "apt-get install", I guess that "apt-get source" does not check if the source is already loaded. Therefore, I would like to add a...
    4. Which is faster - USB-enabled Lexar card with Jumpshot, or conventional USB2 card reader?
      Would like to know which is faster for transfer to PC - a USB-enabled Lexar card ("850kB/s") with a Jumpshot cable, or conventional USB2 card...
    5. Credit card/Debit card validation
      Does anyone know of a PHP routine to validate Credit/Debit cards? I've seen some convoluted Javascript scripts but want a PHP version so validation...
  3. #2

    Default Re: Using wild card in DateTime

    jt wrote:
    > Need help on defining a SQL query statement.
    >
    > I have a field in my table defined as "Date/Time". This is in Access.
    >
    > The data looks like this in the field, "4/19/2004 8:59:17 AM" when
    > entered.
    >
    > When I run the sql query statement with date and time like this,
    > works well. SELECT * FROM [Florida] WHERE Call_Date = #4/19/2004
    > 8:59:17 AM#
    >
    > I want to query the DateTime field by date only and I don't care
    > about the time.
    >
    WHERE Call_Date >= #2004-04-19# AND Call_Date < DateAdd("d",1,#2004-04-19#)

    HTH,
    Bob Barrows
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows Guest

  4. #3

    Default Re: Using wild card in DateTime

    Bob Barrows wrote on 22 apr 2004 in microsoft.public.inetserver.asp.db:
    >> I want to query the DateTime field by date only and I don't care
    >> about the time.
    >>
    >
    > WHERE Call_Date >= #2004-04-19# AND Call_Date <
    > DateAdd("d",1,#2004-04-19#)
    >
    WHERE datediff("d", Call_Date, #2004-04-19#) = 0

    not tested, please be careful

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan. Guest

  5. #4

    Default Re: Using wild card in DateTime

    Evertjan. wrote:
    > Bob Barrows wrote on 22 apr 2004 in
    > microsoft.public.inetserver.asp.db:
    >
    >>> I want to query the DateTime field by date only and I don't care
    >>> about the time.
    >>>
    >>
    >> WHERE Call_Date >= #2004-04-19# AND Call_Date <
    >> DateAdd("d",1,#2004-04-19#)
    >>
    >
    > WHERE datediff("d", Call_Date, #2004-04-19#) = 0
    >
    If you have an index on Call_Date, you should not use this technique because
    it is non-sargable. Avoid using a function on a column in your WHERE clause
    if at all possible because doing so forces a table scan even if an index
    exists.

    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows [MVP] Guest

  6. #5

    Default Re: Using wild card in DateTime

    Bob Barrows [MVP] wrote on 22 apr 2004 in
    microsoft.public.inetserver.asp.db:
    > Evertjan. wrote:
    >> Bob Barrows wrote on 22 apr 2004 in
    >> microsoft.public.inetserver.asp.db:
    >>
    >>>> I want to query the DateTime field by date only and I don't care
    >>>> about the time.
    >>>>
    >>>
    >>> WHERE Call_Date >= #2004-04-19# AND Call_Date <
    >>> DateAdd("d",1,#2004-04-19#)
    >>>
    >>
    >> WHERE datediff("d", Call_Date, #2004-04-19#) = 0
    >>
    > If you have an index on Call_Date, you should not use this technique
    > because it is non-sargable. Avoid using a function on a column in your
    > WHERE clause if at all possible because doing so forces a table scan
    > even if an index exists.
    >
    Right. forgot about that.

    If the above is used frequently, wouldn't it be better to add a field
    containing just the date?

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan. Guest

  7. #6

    Default Re: Using wild card in DateTime

    Evertjan. wrote:
    > Bob Barrows [MVP] wrote on 22 apr 2004 in
    > microsoft.public.inetserver.asp.db:
    >
    >> Evertjan. wrote:
    >>> Bob Barrows wrote on 22 apr 2004 in
    >>> microsoft.public.inetserver.asp.db:
    >>>
    >>>>> I want to query the DateTime field by date only and I don't care
    >>>>> about the time.
    >>>>>
    >>>>
    >>>> WHERE Call_Date >= #2004-04-19# AND Call_Date <
    >>>> DateAdd("d",1,#2004-04-19#)
    >>>>
    >>>
    >>> WHERE datediff("d", Call_Date, #2004-04-19#) = 0
    >>>
    >> If you have an index on Call_Date, you should not use this technique
    >> because it is non-sargable. Avoid using a function on a column in
    >> your WHERE clause if at all possible because doing so forces a table
    >> scan even if an index exists.
    >>
    >
    > Right. forgot about that.
    >
    > If the above is used frequently, wouldn't it be better to add a field
    > containing just the date?
    Not really, considering the overhead that would be required to maintain this
    field, especially considering that it won't gain you much in the way of
    performance if you already have an index on the Call_Date field. The >=, <
    criterion I suggested is sargable and will use the index on Call_Date if it
    exists.

    I have no problem with denormalizing a table if it has a substantial impact
    on query performance, enough to offset the increase in overhead required to
    maintain the denormalized data. In this case however, I do not think it is
    warranted.

    For example, if you had a frequently run query (or better yet, set of
    queries) that required all the records from a particular month (ignoring the
    year), then I would see a reason to break out the month into its own indexed
    field. There is no way to create a sargable criterion that will filter
    records for a specified month disregarding of the year.

    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows [MVP] Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139