如何将 nvarchar 数据类型转换为数字

How to convert nvarchar datatype to numeric

我需要将 nvarchar 数据类型转换为数字,因为当我尝试以这种方式转换它时出现错误。

   cast(memberid as numeric(10,0) as memberid

这会以同样的方式工作吗?

   case when ISNUMERIC(memberid) = 1 then cast(memberid as numeric(10,0)) else NULL end As memberid

如有任何帮助,我们将不胜感激!!谢谢!

在 Sql Server 2012+ 中使用:try_convert(numeric(10,0),memberid)


在 Sql Server 2012 及更高版本中:当转换失败而不是错误时,其中每一个都会 return null