Groups | Blog | Home
all groups > sql server programming > january 2004 >

sql server programming : Help with a Select


Kissi
1/6/2004 11:59:38 PM
Could anyone help me with this Please, below is the code I've been trying
but it's not working. A user selects a start date and an end date. Table has
a BeginField and EndField. If dates selected by the user exist in the
database, the prompt user(Dates not available).

Dim strSQL As String
Dim strDateStart As String
Dim strDateEnd As String
strDateStart = InputBox("Enter Begin Date ")
If strDateStart = vbNullString Then
Exit Sub
Else
strDateEnd = InputBox("Enter End Date")
If strDateEnd = vbNullString Then
Exit Sub
strSQL = "SELECT * FROM Driver " & _
"WHERE DateBegin BETWEEN strDateStart AND strDateEnd' "

Set cmdDriver.ActiveConnection = conDriver
cmdDriver.CommandType = adCmdText
cmdDriver.CommandText = strSQL
rsDriver.Open cmdDriver
rsDriver.Requery
If rsDriver.EOF Then
MsgBox "Date Available.", vbOKOnly
Else
MsgBox "Date Not Available.", vbOKOnly
End If
End If
End If
End Sub

Ata
1/7/2004 5:29:57 AM
[quoted text, click to view]
Why is there a single quote after strDateEnd?
Why are you putting strDateStart and StrDateEnd, which are VB variables,
inside your SQL query? Should you not be putting there contents more like:

"WHERE DateBegin BETWEEN '" & strDateStart & "' AND '" & strDateEnd & "'"


--
Ata R
Parvan Consulting Inc
NO_SPAMar_alias001@NO_SPAMparvan.net



[quoted text, click to view]

David Portas
1/7/2004 8:05:12 AM
In addition to Ata's reply, there are good reasons to avoid using BETWEEN
with datetime values:

http://www.aspfaq.com/2280

--
David Portas
------------
Please reply only to the newsgroup
--

AddThis Social Bookmark Button