Solved

select error:syntax error during explicit conversion of varchar value '11-13-200723:59:59' to a datetime field

Posted on 2009-04-13
4
2,613 Views
Last Modified: 2012-05-06
This a datawindow sql for a report.It looks like somehow the date conversion code we have in the query is concatenating the date/time correctly in some cases and others it doesnt work and we get no space between them.  It happens when we enter dates greater than 11/10/2007 for the to-date
I was thinking of  padding a space to the beginning of the time fields hardcoded in the SQL.
What you guys think.
select .....

where

 (itemhst.crdtstmp >= convert(datetime,convert(varchar(10),:a_da_fromdate) + '00:00:00')) and

         (itemhst.crdtstmp <= convert(datetime,convert(varchar(10),:a_da_todate) + '23:59:59')) 
 

crdtstmp  is a datetime field. The database is Sybase ASE 12.5. Powerbuilder ver 9

Open in new window

datawinerror.bmp
0
Comment
Question by:HARLIBRA
4 Comments
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 500 total points
Comment Utility
Yes have to add a space in between the values along with proper style definition so that Month and day wont be confused out.

Try out this query:

 (itemhst.crdtstmp >= convert(datetime,convert(varchar(10),:a_da_fromdate, 101) + ' 00:00:00',101)) and
         (itemhst.crdtstmp <= convert(datetime,convert(varchar(10),:a_da_todate,101) + ' 23:59:59',101))
0
 
LVL 19

Expert Comment

by:grant300
Comment Utility
Test the SQL in an interactive tool first so you don't get bound up with the reporting facility.  It will make things much easier.

Regards,
Bill
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Read about achieving the basic levels of HRIS security in the workplace.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now