Set variable date range in query?

A

Abel MacAdam

Hi,

At the moment I'm looking into getting data from a database into Excel. One
problem I have is entering the date range in which the data from the database
must adhere to. I do not want to have to open the query each time to change
the start and finish dates.

When I have two ranges in a sheet, called 'start' (imagine it in cell B1)
and 'finish' (placed in cell B2), how should I read 'start' and 'finish' into
the query?

Should the WHERE clause have something like:
SELECT ...
DATEADD (T.Created, INTERVAL HOUR (TIMEDIFF(TIME(NOW(), UTC_TIME())) HOUR
CREATED,
DATEADD (T.Resolved, INTERVAL HOUR (TIMEDIFF(TIME(NOW(), UTC_TIME()))
HOUR RESOLVED
WHERE "start" <= CREATED
AND CREATED <= "finish"

Note: T.Created and T.Resolved are (date) fields in the database I query.

Who knows what I need to fill in in the WHERE clause?

Abel
 
J

Jacob Skaria

Dim dtStart
Dim dtEnd

dtStart = cDate(ActiveSheet.Range("B1"))
dtEnd = cDate(ActiveSheet.Range("B2"))

and use this variables in query.

If this post helps click Yes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top