SQL取得最大排序数字并累加1的自定义函数

来源:互联网 发布:php精品课程 编辑:程序博客网 时间:2024/06/15 06:53

/**********************************************************************
函数名:GetMaxSqrt(@SqrtType)
参数:@SqrtType定义取值的表
    @MaxSqrtID:返回max(sqrt)+1
返回 数字
power by adpost
email:zrsz@hotmail.com
**********************************************************************/
CREATE FUNCTION GetMaxSqrt(@SqrtType as int)
RETURNS int
WITH ENCRYPTION
as
BEGIN
 declare @MaxSqrtID as int
 if(@SqrtType=1)
 begin
  select @MaxSqrtID = max(CategorySqrt) from LXBIZ_Category
 end
 if(@SqrtType=2)
 begin
  SELECT @MaxSqrtID = max(SubClassSqrt) FROM LXBIZ_SubClass
 end
 if(@MaxSqrtID is null)
 begin
  select @MaxSqrtID = 0
 end
 return @MaxSqrtID+1
END

 

原创粉丝点击