Problem with between function with date timepicker
-
hello i am using SQL server 2005 as my back end now i want report of like from this date to this date...for that i wrote query like format of my date is dd/MMM/yyyy If optn1.Checked = True Or optn3.Checked = True Then sqlstr="select * from des_mast" sqlstr = sqlstr & "where pickup_date between '" & Me.dtp1.Value & "' and '" & Me.dtp2.Value & "'" End If but while executing this query shows an error message like "incorrect syntax near the keyword 'between'" please suggest i cant get where the problem is thank you
-
hello i am using SQL server 2005 as my back end now i want report of like from this date to this date...for that i wrote query like format of my date is dd/MMM/yyyy If optn1.Checked = True Or optn3.Checked = True Then sqlstr="select * from des_mast" sqlstr = sqlstr & "where pickup_date between '" & Me.dtp1.Value & "' and '" & Me.dtp2.Value & "'" End If but while executing this query shows an error message like "incorrect syntax near the keyword 'between'" please suggest i cant get where the problem is thank you
-
hello i am using SQL server 2005 as my back end now i want report of like from this date to this date...for that i wrote query like format of my date is dd/MMM/yyyy If optn1.Checked = True Or optn3.Checked = True Then sqlstr="select * from des_mast" sqlstr = sqlstr & "where pickup_date between '" & Me.dtp1.Value & "' and '" & Me.dtp2.Value & "'" End If but while executing this query shows an error message like "incorrect syntax near the keyword 'between'" please suggest i cant get where the problem is thank you
nazimghori wrote:
format of my date is dd/MMM/yyyy
The format of your sql or the format of your datetimepicker?
nazimghori wrote:
If optn1.Checked = True Or optn3.Checked = True Then
You dont need to compare a booleanvalue with true or false Just do it like this: If optn1.Checked Or optn3.Checked Then Or even better: If optn1.Checked OrElse optn3.Checked Then
nazimghori wrote:
sqlstr="select * from des_mast" sqlstr = sqlstr & "where pickup_date between '" & Me.dtp1.Value & "' and '" & Me.dtp2.Value & "'"
After concatenating this, i dont think youll get a space between des_mast and where, youll get des_mastwhere Also, have you tryed using # for the date values: between #12/12/2009# and #12/12/2009# If you still cant get it to work, you can test manually the query in sql server managment studio
Alexei Rodriguez