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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax error converting character string to smalldatetime data type 1

Status
Not open for further replies.

dom24

Programmer
Aug 5, 2004
218
0
0
GB
I'm trying to take the day, month and year from a querystring and convert it into a data so that I can match it with a date in a record of the database.

What I write the strSQL to the screen I get the following:

SELECT * FROM Bookings WHERE StartDate = '28' + '1' + '2005'

and then the error message:

Syntax error converting character string to smalldatetime data type

I know it's because the string is not inthe format dd/mm/yy but I don't know how to change it to that format so i'm using the functions year(now()), etc.

My sql statement looks like this:

strSQL = "SELECT * FROM Bookings WHERE StartDate = '" & Request.Querystring("Day") & "' + '" & Request.Querystring("Month") & "' + '" & Request.Querystring("Year") & "'"

Any help would be appreciated. Thanks



 
Try this:
Code:
SELECT * FROM Bookings
   WHERE
    DatePart(year,StartDate) = '2005' and
    DatePart(month,StartDate) = '01' and
    DatePart(day,StartDate) = '28'
 
That gets rid of the error message yeah thanks.
But it still doesn't match it to my date in the records in the database. I've got a date set as smalldatetime 28/01/2005 and it's not finding it???
 
Never mind, I got them the wrong way round!
Works a treat! Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top