常用存储过程2(获取编码级次)
Create Proc GetNumberLevel
@num varchar(100),
@level int output
as
set @level=1
declare @c char(1),@i int,@section varchar(20)
set @i=1
set @section=''
while @i<=len(@num)
begin
if substring(@num,@i,1)='.'
begin
if len(@section)=0
raiserror ('编码格式错误',16,1) --某一节的编码为空
set @level=@level+1
set @section=''
end
else
set @section=@section+substring(@num,@i,1)
set @i=@i+1
end
if len(@section)=0
raiserror ('编码格式错误',16,1) --最后一节的编码为空
GO
@num varchar(100),
@level int output
as
set @level=1
declare @c char(1),@i int,@section varchar(20)
set @i=1
set @section=''
while @i<=len(@num)
begin
if substring(@num,@i,1)='.'
begin
if len(@section)=0
raiserror ('编码格式错误',16,1) --某一节的编码为空
set @level=@level+1
set @section=''
end
else
set @section=@section+substring(@num,@i,1)
set @i=@i+1
end
if len(@section)=0
raiserror ('编码格式错误',16,1) --最后一节的编码为空
GO