Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Syntax error converting datetime from character string.


Message #1 by Joshua Prentice <JPrentice@e...> on Fri, 22 Feb 2002 09:02:04 -0500
> Joshua,
> 
> Some initial comments:
> 
> Format your dates in ISO format: yyyy/mm/dd rather than using CDate()
> You can use a function like this:
> www.adopenstatic.com/resources/code/formatdate.asp
> to do this
> 
> Secondly, I don't think you should trust user input like you are. 
Validate
> all user date before you put it directly into an SQL statement. Something
> like:
> www.adopenstatic.com/resources/code/UIValidation.asp
> might help.
> 
> SELECT * isn't a great idea either...
> 
> That all said: do you only get this error trying to sort on e.[name], or 
on
> any field?
> 
> Cheers
> Ken
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> From: "Joshua Prentice" <JPrentice@e...>
> Subject: [sql_language] Syntax error converting datetime from character
> string.
> 
> 
> : 'm getting this error and can not figure out what's going on.  I have 
code
> : that simply sorts a recordset depending on which column the user 
chooses
> to
> : sort from.  I then send it to a procedure like this:
> :
> : sql = "EXEC port_client_sum_eval @Begin = '" &
> : cdate(Request.QueryString("BeginDt")) & "', @End = '" &
> : cdate(Request.QueryString("EndDt")) & "', @Sort = '" &
> : Request.QueryString("Sort") & "', @Company = 'MIC', " sql = sql 
& "@OHigh
> 
> : '" & Request.QueryString("OverallHigh") & "', @OLow = '" &
> : Request.QueryString("OverallLow") & "', @MHigh = '" &
> : Request.QueryString("MaterialsHigh") & "', @MLow = '" &
> : Request.QueryString("MaterialsLow") & "', @IHigh = '" &
> : Request.QueryString("InstructorHigh") & "', @ILow = '" &
> : Request.QueryString("InstructorLow") & "' "
> :
> : which is response written as:
> :
> : EXEC port_client_sum_eval @Begin = '3/1/1997', @End = '2/21/2002', 
@Sort 
> : 'txtCourse', @Company = 'MIC', @OHigh = '10', @OLow = '0', @MHigh 
= '10',
> : @MLow = '0', @IHigh = '10', @ILow = '0'
> :
> : The procedure is:
> : CREATE PROC port_client_sum_eval
> : @Begin smalldatetime,
> : @End smalldatetime,
> : @Company char(3),
> : @OHigh int,
> : @OLow int,
> : @MHigh int,
> : @MLow int,
> : @IHigh int,
> : @ILow int,
> : @Sort varchar(10)
> : AS
> : SELECT e.[Name], v.*,  ie.EventID, ie.SubeventID, ie.IAvg, 
ie.FirstName,
> : ie.LastName
> : FROM (esinet.dbo.vSubEvnt v INNER JOIN esinet.dbo.tblInsEval ie ON
> : (v.SubEventID = ie.SubEventID)
> : AND (v.EventID = ie.EventID))
> : INNER JOIN pwpro.dbo.Event e ON v.EventID = e.EVENTID
> : WHERE ((v.Begin_Date) >= @Begin) AND ((v.Begin_Date) <= @End)
> : AND ((v.OAvg) <= @OHigh) AND ((v.OAvg) >= @OLow) AND ((v.MAvg) <= 
@MHigh)
> : AND ((v.MAvg) >= @MLow)
> : AND ((ie.IAvg) <= @IHigh) AND ((ie.IAvg) >= @ILow) AND left
(ie.eventID, 3)
> 
> : @Company
> : ORDER BY
> : CASE @Sort
> :   When  'Date' then v.Begin_Date
> :   When  'OAvg' then v.OAvg
> :   When  'Instr' then ie.LastName
> :   When  'txtCourse' then e.[name]
> :   When  'MAvg' then v.MAvg
> :   When  'IAvg' then IAvg
> : When  'RecPcnt' then v.RecPcnt
> : Else v.Begin_Date
> : END
> :
> : Everything works perfectly, except I'm getting the above error when 
trying
> : to sort by my varchar fields (e.[name] and ie.LastName).
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
Ken --

Thanks for the tips.  To answer your question, I get it when searching 
only on either e.[name] or ie.Lastname, which are the only varchar fields 
of the bunch.

  Return to Index