sql server - 检查是否可以进行强制转换 [英] sql server - check to see if cast is possible
本文介绍了sql server - 检查是否可以进行强制转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码将 nvarchar 转换为整数:
I have the following code to cast nvarchar to integer:
cast(@value as int)
但是我无法控制参数@value,因此代码可能会失败.无论如何,在进行演员表之前是否可以检查是否可以进行演员表?
However I have no control of the parameter @value, hence the code might fail. Is there anyway to check if a cast is possible before doing a cast?
推荐答案
好吧,在 SQL Server 2012 中,您可以使用新的 TRY_CAST(),但对于 SQL Server 2008,您应该能够使用 ISNUMERIC(),然后包括对未通过该测试的值的处理.
Well, in SQL Server 2012 you could use the new TRY_CAST(), but with SQL Server 2008, you should be able to use ISNUMERIC(), and then include handling for values that do not pass that test.
这篇关于sql server - 检查是否可以进行强制转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文