简体   繁体   English

消息156,级别15,状态1,过程ShowDirectorateList,第739行关键字'END'附近的语法不正确

[英]Msg 156, Level 15, State 1, Procedure ShowDirectorateList, Line 739 Incorrect syntax near the keyword 'END'

I make a procedure and i got alot error msg like 我做了一个程序,我收到了很多错误消息,例如

Msg 156, Level 15, State 1, Procedure ShowDirectorateList, Line 739 Incorrect syntax near the keyword 'END'. 消息156,级别15,状态1,过程ShowDirectorateList,第739行关键字'END'附近的语法不正确。

there is my code pls help me fix it: 有我的代码请帮助我修复它:

    --List ALL
    IF (@iType = 1 AND @iStatus=2)
    BEGIN
        WITH Allboth AS
        (
        SELECT ROW_NUMBER() OVER (ORDER BY [sName],[iDirectorateID]) AS RowNum
            ,[iDirectorateID]
            ,[sName] 
            ,[sAddress1] 
            ,[iPostCode] 
            ,[sLeadContact] 
            ,[iStatus] 
        FROM [dbo].[Directorate] Dir
            ,[dbo].[Contact] Con
            ,[dbo].[Address] Ad
            ,[dbo].[Detail] Det
        WHERE Dir.iContactID = Con.iContactID
        AND Con.iDetailID = Det.iDetailID
        AND Con.iAddressID = Ad.iAddressID
        ) 
        Insert Into @_FisrtTable
    END

i want select data from database and put in @_FirstTable 我想从数据库中选择数据并放入@_FirstTable

    DECLARE @_FisrtTable Table
(
     [RowNum] int NULL
    ,[iDirectorateID] int NULL
    ,[sName] nvarchar(50) NULL
    ,[sAddress1] nvarchar(50) NULL
    ,[iPostCode] int NULL
    ,[sLeadContact] nvarchar(50) NULL
    ,[iStatus] int NULL
)
DECLARE @_FisrtTable TABLE (
    [RowNum] INT NULL,
    [iDirectorateID] INT NULL,
    [sName] NVARCHAR(50) NULL,
    [sAddress1] NVARCHAR(50) NULL,
    [iPostCode] INT NULL,
    [sLeadContact] NVARCHAR(50) NULL,
    [iStatus] INT NULL
)

IF (@iType = 1 AND @iStatus = 2) BEGIN

    ;WITH Allboth AS ( -- missing ";"
        SELECT
            ROW_NUMBER() OVER (ORDER BY [sName], [iDirectorateID]) AS RowNum,
            [iDirectorateID],
            [sName],
            [sAddress1],
            [iPostCode],
            [sLeadContact],
            [iStatus]
        FROM [dbo].[Directorate] Dir,
             [dbo].[Contact] Con,
             [dbo].[Address] Ad,
             [dbo].[Detail] Det
        WHERE Dir.iContactID = Con.iContactID
            AND Con.iDetailID = Det.iDetailID
            AND Con.iAddressID = Ad.iAddressID
    )
    INSERT INTO @_FisrtTable
    SELECT * FROM Allboth -- missing "SELECT" from CTE

END

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Msg 156,Level 15,State 1,Procedure inventory,Line 6 [Batch Start Line 2]关键字'Where'附近的语法不正确 - Msg 156, Level 15, State 1, Procedure inventory, Line 6 [Batch Start Line 2] Incorrect syntax near the keyword 'Where' 消息156,级别15,状态1,过程CLR_TRIGGER_NAUDOJASI,第1行关键字“插入”附近的语法错误 - Msg 156, Level 15, State 1, Procedure CLR_TRIGGER_NAUDOJASI, Line 1 Incorrect syntax near the keyword 'insert' 消息 156,级别 15,State 1,第 5 行关键字“LEFT”附近的语法不正确。 消息 156,级别 15,State 1,第 6 行 'b' 附近的语法不正确 - Msg 156, Level 15, State 1, Line 5 Incorrect syntax near the keyword 'LEFT'. Msg 156, Level 15, State 1, Line 6 Incorrect syntax near 'b' 消息156,级别15,状态1,第50行关键字“ GROUP”附近的语法错误 - Msg 156, Level 15, State 1, Line 50 Incorrect syntax near the keyword 'GROUP' 消息156,级别15,状态1,行2493关键字“ ON”附近的语法错误 - Msg 156, Level 15, State 1, Line 2493 Incorrect syntax near the keyword 'ON' 消息156,级别15,状态1,第16行关键字“ IF”附近的语法错误 - Msg 156, Level 15, State 1, Line 16 Incorrect syntax near the keyword 'IF' 消息156,级别15,状态1,第22行在关键字“具有”附近的语法错误 - Msg 156, Level 15, State 1, Line 22 Incorrect syntax near the keyword 'having' 消息 156,级别 15,状态 1,第 7 行关键字“BETWEEN”附近的语法不正确 - Msg 156, Level 15, State 1, Line 7 Incorrect syntax near the keyword 'BETWEEN' 消息 156,级别 15,状态 1,第 2 行 关键字“case”附近的语法不正确。 我的 SQL 有什么问题 - Msg 156, Level 15, State 1, Line 2 Incorrect syntax near the keyword 'case'. Whats wrong in my SQL SQL Server:错误消息156,级别15,状态1,第12行关键字“ AS”附近的语法不正确 - SQL Server: error Msg 156, Level 15, State 1, Line 12 Incorrect syntax near the keyword 'AS'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM