SQL字符串中取字母及數字的兩個自定義函數
create function dbo . f _ get _ str(@ s varchar(100))
return varchar(100)
as
begin
while patindex('%[^a-z]%',@s)>0
begin
set @s=stuff(@s,patindex('%[^a-z]%',@s),1,')
end
return @ s
end
go
-test
select dboF_Get_STR ('test。大提示考ABC 123 ABC ')[/br 2008-11-26
函數:獲取字母
*/
創建函數DBO。f _ get _ number(@ svarchar(100))
return int
as[/br]begin
while patindex('%[^0-9]%',@s)>0
begin
set @s=stuff(@s,patindex('%[^0-9]%',@s),1,')
end
return cast(@ s as int)
-test
-select dbo . f _ get _ number(' test ab 3c 123 ab 5c ')[/br/
0條評論