Home >Database >Mysql Tutorial > SQL server自定义函数实例

SQL server自定义函数实例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 17:43:07999browse

create function dbo.t_bh (@str varchar(20)) returns varchar(20) as begin declare @bh varchar(20),@length int,@i int set @length=12-LEN(@str) if LEN(@str)12 begin set @i=0 while @i@length begin set @str='0'+@str set @i=@i+1 end return @str

create function dbo.t_bh (@str varchar(20))

returns varchar(20)

as

begin

 declare @bh varchar(20),@length int,@i int

 set @length=12-LEN(@str)

  if LEN(@str)

   begin

   set @i=0

   while @i

    begin

     set @str='0'+@str

     set @i=@i+1

    end

    return @str

   end

   else if isnull(@str,0)=0

   begin

   set @str='000000000000'

   return @str

   end

   else

    begin

    return @str

    end

  return @str

end

 

--select dbo.t_bh('000022')

,美国空间,网站空间,美国服务器
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn