PDA

View Full Version : Creating a List Array for use in an ADO query



mferrisi
08-03-2007, 10:46 AM
I am trying to run a query that returns the data only on certain dates. I've done it this way before with strings (ie to return string values from the datadase) but it doesn't seem to like the string with dates that I create. Am I missing something?

My error message is:
"The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value."

I don't think there is an Array List in VBA?


t = SDate & ", " & FDate & ", " & EDate

cmd.CommandText = "SELECT hist_date, hist_price " & _
"FROM history " & _
"WHERE (name='TheName') AND (type='accounting') " & _
AND (date ='" & t & "')"

mvidas
08-03-2007, 11:01 AM
What about something like cmd.CommandText = "SELECT hist_date, hist_price " & _
"FROM history " & _
"WHERE name='TheName' AND type='accounting' " & _
"AND (date = " & SDate & " OR date = " & FDate & " OR date = " & EDate & ")"

mferrisi
08-03-2007, 11:49 AM
The problem though is that I might be querying from 100's of dates, which was why I was hoping to do something a bit more compact

Bob Phillips
08-03-2007, 12:01 PM
Surely, if there are hundreds of dates, it woulkd be more practical to write them to a database table, and then use that table in the query.