Reputation: 1415
I'm try to perform a TRY_CAST
in SQL Server 2005. The query will look like:
SELECT TRY_CAST((select bla bla bla expression) as int)
The expression inside the try_cast
might return some strings or something which cannot be converted as INT, that's why I need it (obviously :) ). Unfortunately I wrote my big query for SQL Server 2012, but now I need to use it on a SQL Server 2005.
Is there a workaround?
Thank you!
Upvotes: 1
Views: 1671
Reputation: 1415
In the end I solved with:
case when IsNumeric(Expression)=1
then cast(Expression as int)
else NULL
end
Upvotes: 2