sqlServer 函数

sqlServer 函数

 

ALTER FUNCTION [dbo].[IM_fn_SRNO](@reg VARCHAR(64),@inv VARCHAR(64))
RETURNS [varchar](256) WITH EXECUTE AS CALLER
AS
begin
declare @Name varchar(256)
declare @regNew varchar(256)
select @Name =rnum from (  select row_number() over(ORDER BY INVOICECODE) as rnum ,  INVOICECODE  
from  CM_FAREDETAIL  where regcode = @reg group by INVOICECODE  )  t where t.INVOICECODE =@inv

if @name >1
BEGIN
  set @regNew = @reg +'00' + @name
END
ELSE
BEGIN
    set @regNew = @reg
END

    return @regNew
    END

posted @ 2021-08-27 16:04  leolzi  阅读(40)  评论(0编辑  收藏  举报