Closed. This question needs debugging details . It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem . This will help others answer the question.
Closed 22 days ago.
The community is reviewing whether to reopen this question as of 19 days ago.
Improve this question
In my SQL Server database, there is a varchar column begintime
which has value like 2023/07/10
in table t1.
I use
select cast(begintime as date) from t1
to convert it to date and it return error message said some data can't be converted. After checking all values in the table finally I found the reason. Some data 's length is 12 instead of 10,with a return and blank character in the end.I wonder is there some tools in sql server studio which can fast locate the bad data? Any help?
Thanks
1条答案
按热度按时间esbemjvw1#
use
CAST
orCONVERT
built in functions to make2023/7/10
as2023/07/10
above line's gives out put if date is valid to convert else gives error response.
you may use
TRY_CAST
orTRY_CONVERT
this will give you out put if date is valid to convert else returnNULL