Results 1 to 6 of 6

Thread: [RESOLVED] Search within date range only

  1. #1

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Resolved [RESOLVED] Search within date range only

    Is there a way I can merge this two queries?


    strSQL = "SELECT * FROM TABLENAME WHERE DATEFIELD BETWEEN #" & dtpFrom.Value & "# AND #" & dtpTo.Value & "#"


    strSQL = "SELECT * FROM TABLENAME WHERE ANYFIELD LIKE 'ANYKEYWORD%' ORDER BY ID"


    The first query is for date range. The next query is a normal query for keywords. I want to use the second query BUT will only search between the date ranges of the first query.

    If only I could merge the two. Is this possible? Something like this.

    strSQL = "SELECT * FROM TABLENAME WHERE ANYFIELD LIKE 'ANYKEYWORD%' AND WHERE DATEFIELD BETWEEN '" & dtpFrom.Value & "' AND '" & dtpTo.Value & "'" ORDER BY ID"

    By the way, I am using SQL Server. Thanks for the help.

  2. #2
    Addicted Member
    Join Date
    Aug 2007
    Location
    India
    Posts
    141

    Re: Search within date range only

    You can use this
    strSQL = "SELECT * FROM TABLENAME WHERE (DATEFIELD BETWEEN '" & dtpFrom.Value & "' AND '" & dtpTo.Value & "'") AND (ANYFIELD LIKE 'ANYKEYWORD%') ORDER BY ID
    Do Good. Be Good. The World is yours.

  3. #3

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Search within date range only

    Ahh. Is that it? You mean im only missing a parenthesis? I'll try that out.

  4. #4

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Search within date range only

    Thanks! Post rated. I made myself a fool.

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: [RESOLVED] Search within date range only

    The parenthesis aren't strictly needed, but are a good idea (they make it clearer, and reduce mistakes when you have a mixture of And/Or).

    The important thing is that you had WHERE twice, and it should only be used once.

  6. #6

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: [RESOLVED] Search within date range only

    Yeah. Thanks a bunch!

Posting Permissions

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



Click Here to Expand Forum to Full Width