Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I select on a SQL Datetime field in Excel Query?

I can't seem to find the correct format for the date so that it will actually
exclude or include certain dates.
I am trying to do a parameter query where I can then enter a date range of
the records I want this time.
This is a database query from a SQL table.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default How do I select on a SQL Datetime field in Excel Query?

Record adding a query table then edit the query to get the values you want

e.g.

Sub AddDateRangeQuery(dtStart as date, dtEnd as date)
Dim strDateStart as string
Dim strDateEnd as string

strDateStart = format("yyyy-mm-dd",dtStart)
strDateEnd = format("yyyy-mm-dd",dtEnd)

'the query connection stuff goes here, but replace the command text line
with something like this
'watch out for the single quote marks in this statement around the dates
CommandText = Array("SELECT * FROM GetSecurityRSIDaily WHERE SecurityIndex=1
" & _
"AND PeriodEnd BETWEEN '" & strDateStart & "'AND '" & strDateEnd &
"' ORDER BY PeriodEnd DESC"
'remainder of the query connection stuff here

End Sub

If you want to get just a specific few days, that are non-contiguous, have a
look at the IN clause. I would probably add all the selected dates to a
collection, then pass the collection to the sub that builds the query and
have the sub build the SQL command string in this case.
e.g.
PeriodEnd IN ('2004-01-01','2004-06-30','2004-02-29')

If you need help on SQL, you can download Books Online for free from MS.

Robin Hammond
www.enhanceddatasystems.com

"Smorgan" wrote in message
...
I can't seem to find the correct format for the date so that it will
actually
exclude or include certain dates.
I am trying to do a parameter query where I can then enter a date range of
the records I want this time.
This is a database query from a SQL table.



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
MS Query DateTime String Dean Excel Worksheet Functions 1 January 23rd 06 12:07 PM
How do I create a query field in Excel Sean Excel Discussion (Misc queries) 1 July 20th 05 08:47 PM
Removing characters from datetime field Sujesh Excel Discussion (Misc queries) 3 July 14th 05 03:22 PM
Using datetime fields as parameters in a query... Olaf Stetzer Excel Programming 1 January 7th 04 02:55 PM
datetime in query Ling[_2_] Excel Programming 1 August 8th 03 05:08 PM


All times are GMT +1. The time now is 07:09 PM.

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"