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,806 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
ID: 24133839
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
ID: 24134509
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…

730 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