Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Set variable date range in query?

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Set variable date range in query?

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
--------------
Jacob Skaria


"Abel MacAdam" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to make Date Range variable in VBA SQL Query Tim French Excel Programming 1 September 14th 06 06:31 PM
remote query & date range? Linn Kubler Excel Programming 0 March 7th 06 03:19 PM
How do I enter a date range ie -7 from current date in MS QUERY notsmartenough Excel Discussion (Misc queries) 1 November 11th 05 10:17 PM
HOW DO I CHANGE QUERY DATA TO A DATE RANGE? GRABrendan Excel Worksheet Functions 4 September 27th 05 04:43 AM
Changing fixed date with a variable in a ODBC Query Hande & Tolga Excel Programming 1 September 22nd 03 11:00 AM


All times are GMT +1. The time now is 11:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"