码迷,mamicode.com
首页 > 数据库 > 详细

Sql Server 判断字符串是否可以转数字

时间:2017-11-13 20:05:29      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:ati   fun   tin   creat   dex   系统   cti   null   arc   

主要是在sql server的内置系统函数ISNUMERIC的基础上,将例外的“+”、“-”、“$”等进行也进行判断。

CREATE FUNCTION [dbo].[fn_IsNumberic]
(
@str nvarchar(max)
)
RETURNS int
AS
BEGIN
declare @res int
set @res=case when ISNUMERIC(isnull(@str,0))=1 then
case when PATINDEX(‘%[^0-9.]%‘,rtrim(ltrim(isnull(@str,0))))=0 then 1
end
end
return isnull(@res,0)
END

GO

Sql Server 判断字符串是否可以转数字

标签:ati   fun   tin   creat   dex   系统   cti   null   arc   

原文地址:http://www.cnblogs.com/jearay/p/7827336.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!