我想寫一個存儲過程返回存款記錄一個特定的人,存款的那個人,並且存款的那個人的行數目。參數@personID
總是提供正確PERSONID;然而@SpecificRow
是0(意思是:返回最近的存款)或行號(意思是:在這個特定的行返回記錄)。SQL Server存儲過程語法錯誤
腳本:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [schema].[procedure]
@personID varchar(5),
@SpecificRow int,
@RowNumber INT OUTPUT,
@RowCount INT OUTPUT
AS
BEGIN
IF OBJECT_ID('#TempSortedDeposits') IS NOT NULL
DROP Table #TempSortedDeposits
-- get all deposits with record number into temp file for specific personID
SELECT
ROW_NUMBER() OVER (ORDER BY Date ASC) AS RecordNo, *
INTO
#TempSortedDeposits
FROM
persons.Deposits
WHERE
personID = @personID
-- get record count in file
SELECT @RowCount = COUNT(personID)
FROM persons.Deposits
WHERE personID = @personID
IF @SpecificRow = 0 --get most recent record
SET @RowNumber = @RowCount;
ELSE
--get record by rownumber
SET @RowNumber = @SpecificRow;
SELECT *
FROM #TempSortedDeposits
WHERE RecordNo = @RowNumber
END
當我嘗試運行ALTER語句,我得到以下錯誤:
Msg 102, Level 15, State 1, Procedure procedure, Line 33 [Batch Start Line 9]
Incorrect syntax near ''.
任何見解?
謝謝。
檢查什麼傳遞給帕拉姆@personID? –
@FullMoonFisher這不應該造成編譯錯誤,只是執行。 – scsimon