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'.
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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.