简体   繁体   English

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

[英]How to convert nvarchar datatype to numeric

I need to convert an nvarchar datatype to numeric since it's giving me an error when I tried to convert it this way. 我需要将nvarchar数据类型转换为数字,因为在尝试以这种方式进行转换时会给我一个错误。

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

would this work the same way? 这样会以同样的方式工作吗?

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

any help would be appreciated!! 任何帮助,将不胜感激!! Thanks! 谢谢!

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


In Sql Server 2012 and up: each of these will return null when the conversion fails instead of an error. 在Sql Server 2012及更高版本中:当转换失败而不是错误时,这些参数中的每一个都将返回null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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