常用存储过程3(获取编码的上级编码和短编码)

获取编码的上级编码和短编码,如传入“01.01.123”,返回“01.01”和“123”
Create
  Proc  GetParentNum
   
@num   varchar ( 100 ),
   
@parentnum   varchar ( 100 ) output,
   
@shortnum   varchar ( 100 ) output
as
declare   @c   char ( 1 ), @i   int
set   @i = len ( @num )
set   @shortnum = ''
while   @i > 0
begin
   
if   substring ( @num , @i , 1 ) = ' . '
   
begin
       
set   @parentnum = substring ( @num , 1 , @i - 1 )
       
return
   
end
   
else
       
set   @shortnum = substring ( @num , @i , 1 ) + @shortnum
   
set   @i = @i - 1
end

GO

你可能感兴趣的:(存储过程)