标量函数
CREATE function [dbo].[UserIDFromName](@UserName nvarchar(20),@UserPass nvarchar(64))
returns int
as
begin
    return (select UserID from UserInfo where UserName=@UserName and UserPass=@UserPass)
    
end;

调用:

create procedure [dbo].[GetUserRole] 
    @UserName nvarchar(20),
    @PassWord nvarchar(64),
    @FuncID int
AS
    set nocount on
 
    declare @UserID int
    set @UserID=Admin.dbo.UserIDFromName(@UserName,@PassWord)

    if @UserID is null
    begin
        select ret=1,msg='用户名或密码错误!'
        return -1
    end
    if not exists (select UserID from UserInfo where UserID=@UserID and IsActive=1)
    begin
        select ret=1,msg='该用户尚未激活,请联系管理员!'
        return -1
    end

    declare @isAdmin bit
    set @isAdmin=(select IsAdmin from UserInfo where UserName=@UserName)
    if @isAdmin=1
    begin
        if @FuncID is not null
            return 4
        else begin
            select ret=1,msg='权限不存在!'
            return -1
        end
    end

    if @FuncID is not null
    begin
        declare @role int
        set @role=(select role from UserRole where UserID=@UserID and FuncID=@FuncID)
        if @role is null 
            set @role=0
        return @role
    end 
    else begin
        select ret=1,msg='权限不存在!'
        return -1
    end

 表值函数:

CREATE FUNCTION [dbo].[Get_BindMaxMemberOrder](@dwRcvUserID as INT)
RETURNS TABLE
AS
    -- 绑定会员,(会员期限与切换时间)
    return (SELECT MAX(MemberOrder) as MaxmemberOrder,MAX(MemberOverDate) as MaxmemberOverDate
    FROM MemberInfo WHERE UserID=@dwRcvUserID)

调用:

-- 绑定会员,(会员期限与切换时间)
        SELECT @MaxMemberOrder=MaxMemberOrder,@MemberOverDate=MaxMemberOverDate
        FROM UserDB.dbo.Get_BindMaxMemberOrder(@dwRcvUserID)

 

posted on 2019-03-16 22:10  松竹梅  阅读(592)  评论(0编辑  收藏  举报