How to fix cast as numeric gives error converting data type varchar to numeric.

 While writing SQL queries, we may get Errors while doing cast(value as data_type) like below:

"converting data type varchar to numeric." 

Sometimes the value will be valid and still you see the error while casting. To fix this error, we can use TRY_CAST instead of CAST function.

Since when the cast fails, the TRY_CAST() function returns NULL while the  cast() function gives an error.

Syntax : 

TRY_CAST(value  AS data_type)

Comments

Popular posts from this blog

how to add new line in google form questions | Fix for next line issue in google form questions

How to add new line in dropdown type question in google forms