简体   繁体   中英

How to perform a TRY_CAST in SQL Server 2005?

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!

In the end I solved with:

case when IsNumeric(Expression)=1
    then cast(Expression as int)
    else NULL
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM