'BEGIN'附近的语法不正确.在TSQL中

0 t-sql sql-server

你好程序员我正在写一个TSQL内联表函数,实际上我在sql中还不够好,当我完成我的代码时我得到了这个错误"'BEGIN'附近的语法不正确." ,任何人都知道解决方案,请给我.顺便说一句,当我点击双击错误消息时,它被选中了最后一个"结束"

create FUNCTION [dbo].[CheckLogin]
(   
    @un varchar(max),
    @pw varchar(max)
)
RETURNS TABLE 
AS
begin
    declare @unexist int, @unpwmatch int, @uid bigint
    declare @uisactivated bit , @uisdeleted bit
    -----
    set @unexist = (select COUNT(UserAccessInfo.UserId) FROM UsersAccessInfo 
    WHERE UserAccessInfo.UserName = @un OR UserAccessInfo.UserEmail = @un)
    ------
    set @unpwmatch = (select count(usersaccessinfo.userid) from usersaccesinfo
    WHERE (usersaccessinfo.UserName = @un) AND (usersaccessinfo.UserPassword = @pw) OR
    (usersaccessinfo.UserEmail = @un) AND (usersaccessinfo.UserPassword = @pw))
    ------
    set @uid =(select usersaccessinfo.userid from usersaccessinfo where
    serAccessInfo.UserName = @un OR UserAccessInfo.UserEmail = @un)
    ------
    if @uid <> Null
    begin
        set @uisactivated =(select usersaccessinfo.userisactivated from usersaccessinfo
        where usersaccessinfo.userid=@uid)
    end
    ------
    if @uid <> null
    begin
        set @uisactivated =(select usersaccessinfo.userisactivated from usersaccessinfo
        where usersaccessinfo.userid=@uid)
    end
    ------
    if @unexist = 0
    begin
        select dbo.getreportbyid('1004')
    end;
    else if @unpwmatch = 0
    begin
        select dbo.getreportbyid('1005')
    end;
    else if @uid<>0
    begin
        if @uisactivated =0
        begin
            select dbo.getreportbyid('1002')
        end;
        else if @uisdeleted = 1
        begin
            select dbo.getreportbyid('1003')
        end;
    end;
    else
    begin
        select ('successful') as report
    end;
    return
end;
Run Code Online (Sandbox Code Playgroud)

RBa*_*ung 6

问题是这些问题:

...
RETURNS TABLE
AS
...
Run Code Online (Sandbox Code Playgroud)

对于四种类型的用户定义函数中的任何一种,这都不是有效语法.

假设您正在尝试定义多语句表值函数,它应如下所示:

...
RETURNS @YourTableName TABLE( <column-definitions>... )
AS
...
Run Code Online (Sandbox Code Playgroud)

然后你的函数语句应该在函数执行RETURN语句之前将函数返回数据放入该表中,它也没有这样做.