[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. :D
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. :)
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
Re: Search within date range only
Ahh. Is that it? You mean im only missing a parenthesis? I'll try that out.
Re: Search within date range only
Thanks! Post rated. I made myself a fool.
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.
Re: [RESOLVED] Search within date range only