Sql – tsql – Conversion failed when converting date and/or time from character string

sqlsql servertsql

I need help with this Conversion failed when converting date and/or time from character string.

I'm trying to run a simple query on an @as_of_date, 10 days ago and 30 days ago. The query works fine if I run it on 3-5 accounts, but any more than that if fails. How do I change my query so that I don't get the conversion error?

Here's my sample query:
enter image description here

Edit

Also tried removing the quotes from the select statement. Still doesn't work.

enter image description here

Best Answer

You can try using ISDATE function to see the input data is a valid date.. Also I don't see in the screenshot how/what is the input.

Related Topic