0

Any Reason why this keeps happening even though the query is valid?... My code is below :)

Select Cdf_Code_Tx, ProjectNo, Convert (Date, [Last Call Back],103) As LastCallBack, (CDF_New_des1_Tx+CDF_New_des2_Tx) As Description
From Products
Inner Join SpecDetails
On CDF_Code_Tx = ProductRef
Inner Join Projects2
On ProjectNo = PID
WHERE  [Last Call Back] = (SELECT MAX(Convert (Date, [Last Call Back], 103))FROM Projects2)
Order By Convert (Date, [Last Call Back], 103) 

When i run this , this error appears!

Msg 241, Level 16, State 1, Line 1 Conversion failed when converting date and/or time from character string.

Needing guidance & Thank you in advance.

7
  • & by keeps happening i mean the question is my problem :) Commented Nov 20, 2013 at 9:26
  • Kindly help us posting exact error to help you added table structure info would be cheery on cake. Commented Nov 20, 2013 at 9:28
  • It seems like [Last Call Back] is a varchar column that really should be a date column. What are the values there (=any non-date values)? Commented Nov 20, 2013 at 9:30
  • Error is now on the table :) Commented Nov 20, 2013 at 9:30
  • Can you check some sample data on [Last Call Back] column? Or you can use ISDATE to check the column contains correct date values Commented Nov 20, 2013 at 9:33

2 Answers 2

1

I think you need to check data for [Last Call Back] column in your table. Check that all data are valid for date conversion or not. I think some string are not valid to convert it into date. So you need to check it by ISDate() function. ISDDate() function will work based on your language and culture like below.

SET LANGUAGE british
SELECT ISDATE('2013-11-20')   /* will return 0 */

SET LANGUAGE us_english
SELECT ISDATE('2013-11-20')   /* will return 1 */

For example, If your column have format like below then it will give error

SELECT CONVERT(DATE, '2013-11-20', 103)
Sign up to request clarification or add additional context in comments.

Comments

1

I think Your Problem is Here Because I seem [Last Call Back] is Varchar() datatype when you convert varchar datatype is date and compare with varchar then you got this error Please you should change Both condition in Same Datatype

WHERE  [Last Call Back] = (SELECT MAX(Convert (Date, [Last Call Back], 103))FROM Projects2)

1 Comment

That was my first thought when reading the query as well. Why on earth convert a column in any format to something else, and then compare it with the original column format?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.