sqlserver创建函数实现只取某个字段的数字部分
[sql] set ansi_nulls on set quoted_identifier on go alter function [dbo].[get_number](@s varchar(100)) returns varchar(100) as begin while patindex('%[^0-9]%',@s) > 0 begin set @s=stuff(@s,patindex('%[^0-9]%',@s),1,'') end return @s end [sql] select dbo.get_number('你好111犊子')
结果:111