主要是在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