Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
3,091 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 2000 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

In this article, we’ll look at how to deploy ProxySQL.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

721 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