常用存储过程1(获取字符串中的第一个数值)
create proc GetFirstNum
@str nvarchar(200),
@num int output
as
declare @i int,@numchar varchar(8)
set @i=0
set @numchar=''
while @i<=len(@str)
begin
declare @c char
set @c=substring(@str,@i,1)
if @c>='0' and @c<='9'
set @numchar=@numchar+@c
else
if len(@numchar)>0
break
set @i=@i+1
end
set @num=cast(@numchar as int)
go
declare @num int
exec GetFirstNum 'hh1234f',@num out
select @num
@str nvarchar(200),
@num int output
as
declare @i int,@numchar varchar(8)
set @i=0
set @numchar=''
while @i<=len(@str)
begin
declare @c char
set @c=substring(@str,@i,1)
if @c>='0' and @c<='9'
set @numchar=@numchar+@c
else
if len(@numchar)>0
break
set @i=@i+1
end
set @num=cast(@numchar as int)
go
declare @num int
exec GetFirstNum 'hh1234f',@num out
select @num