草庵书生

冷眼面对一切,低调!才是最牛B的炫耀!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

取出SQL SERVER字段中的数字

Posted on 2010-04-24 00:44  草庵书生  阅读(1091)  评论(0编辑  收藏  举报

 

 1 CREATE function GetNumberChar(@col varchar(100)) 
 2 returns varchar(20)
 3 as 
 4 begin 
 5 declare @len int,@i int,@rtn varchar(20
 6 set @rtn='' 
 7 set @len=len(@col
 8 set @i=1 
 9 while @i <=@len 
10 begin 
11   if isnumeric(substring(@col,@i,1))=1    
12   begin 
13      set @rtn=@rtn+substring(@col,@i,1
14  end  
15   set @i=@i+1
16 end 
17 
18 if @rtn = '' 
19    set @rtn='0'
20 
21 return @rtn
22    
23 end 
24 
25  
26 
27  
28 
29  
30 
31 
32  
33