Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quick SQL Syntax Problem 1

Status
Not open for further replies.

Polariz666

Programmer
Jul 22, 2004
21
0
0
SE
Hey guys,

I'm having a small bit of trouble with an SQL statement in VB6 and was wondering if any of you could help me.

The statement is as such:

rs.Open "SELECT Name, S, Time, Tid FROM TstArchive WHERE Time >= LIKE '" & passDateToQueryField.Text & "%' AND <= LIKE '" & passDateToQueryField2.Text & "%' ORDER BY Name ASC", db, adLockOptimistic

The passDateToQueryField Text boxes contain dates in the format: 20040924, thus i'm looking through the database for 20040924* strings (The full strings have a time inc seconds on the end: 20040924231401).

This has worked fine in the past however I now want to say between passDateToQueryField.Text and passDateToQueryField2.Text (IE Select all records between these two dates). However I get a syntax error (Missing Operator in Expression).

Any help appreciated.

Mike.
 
You need
[Time] BETWEEN " & passDateToQueryField.Text & "%' AND '" & passDateToQueryField2.Text & "%'

You are really going to come to grief with column names like Name and Time. SQL has nabbed most of the English language as reserved words so you have to put square brackets round the names very often.

 
Yeah ive had this problem loads, but I didnt create the database you see. It's a database that's populated by some other software and i'm simply writing a program that creates statistics from it.

Cheers for the help.

M.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top