CREATE FUNCTION [dbo].[fnIsOpenUserLoggedIn] 
(
-- Add the parameters for the function here
@MeetingID int, @UserID int ,@accesslevel int
)
RETURNS int
AS
BEGIN
DECLARE @RUserID int
DECLARE @tbl TABLE (meetID int, usrID int)

INSERT INTO @tbl
if ( @accesslevel <>6)
begin
select @RUserID = ID  from OpenMeetingUsers where id = @UserID
SELECT distinct l_ml.meetingid  as MeetingID, l_ml.userid FROM  UserMeetingConnections umc 
INNER JOIN OpenMeetingUsers u on umc.UserID = u.ID 
INNER JOIN Log_MeetingLogin l_ml  on ( l_ml.meetingid = @MeetingID and l_ml.userid = u.id ) 
 WHERE u.ID=@RUserID AND l_ml.meetingid=@MeetingID AND l_ml.logoutTime IS NULL and ishost!=1
end
else
begin
select @RUserID = ID from users where  id = @UserID
SELECT distinct l_ml.meetingid  as MeetingID, l_ml.userid FROM  UserMeetingConnections umc 
INNER JOIN Users u on umc.UserID = u.ID 
INNER JOIN Log_MeetingLogin l_ml  on ( l_ml.meetingid = @MeetingID and l_ml.userid = u.id ) 
 WHERE u.ID=@RUserID AND l_ml.meetingid=@MeetingID AND l_ml.logoutTime IS NULL and ishost=1
end
if @@rowcount = 0
return 0
return 1END
提示说if if ( @accesslevel <>6)附近有错误

解决方案 »

  1.   

    INSERT INTO @tbl values(........)
      

  2.   

    CREATE FUNCTION [dbo].[fnIsOpenUserLoggedIn] 
    (
        -- Add the parameters for the function here
        @MeetingID int, @UserID int ,@accesslevel int
    )
    RETURNS int
    AS
    BEGIN
        DECLARE @RUserID int
        DECLARE @tbl TABLE (meetID int, usrID int)
        
        --INSERT INTO @tbl
        if ( @accesslevel <>6)
        begin
            select @RUserID = ID  from OpenMeetingUsers where id = @UserID
            SELECT distinct l_ml.meetingid  as MeetingID, l_ml.userid FROM  UserMeetingConnections umc 
            INNER JOIN OpenMeetingUsers u on umc.UserID = u.ID 
            INNER JOIN Log_MeetingLogin l_ml  on ( l_ml.meetingid = @MeetingID and l_ml.userid = u.id ) 
                 WHERE u.ID=@RUserID AND l_ml.meetingid=@MeetingID AND l_ml.logoutTime IS NULL and ishost!=1
        end
        else
        begin
            select @RUserID = ID from users where  id = @UserID
            SELECT distinct l_ml.meetingid  as MeetingID, l_ml.userid FROM  UserMeetingConnections umc 
            INNER JOIN Users u on umc.UserID = u.ID 
            INNER JOIN Log_MeetingLogin l_ml  on ( l_ml.meetingid = @MeetingID and l_ml.userid = u.id ) 
                 WHERE u.ID=@RUserID AND l_ml.meetingid=@MeetingID AND l_ml.logoutTime IS NULL and ishost=1
        end
        if @@rowcount = 0
            return 0
        return 1END
      

  3.   

    楼上的,返回一个错误:select statements included within a function cannot return data to a client
      

  4.   

    楼上的,返回一个错误:select statements included within a function cannot return data to a client