开发者

SQL stored procedure problems

开发者 https://www.devze.com 2023-03-12 21:10 出处:网络
I have a problem with the following stored procedure CREATE PROCEDURE LockRoots -- Add the parameters for the stored procedure here

I have a problem with the following stored procedure

CREATE PROCEDURE LockRoots
    -- Add the parameters for the stored procedure here
    @lock uniqueidentifier,
    @count int
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    UPDATE R
    SET R.[Lock] = @lock
    FROM 
    (
        SELECT TOP @count *
        FROM [Root] as R
        --LEFT JOIN [Container] as C ON R.ID = C.RootID
        WHERE [Lock] IS NULL
        --ORDER BY NEWID()
    );
END
GO

The problem occurs with开发者_运维知识库 "SELECT TOP @count *", why can't I "select top @VariableAmount" of records?


Need parenthesis...

...
SELECT TOP (@count) *
...

Note: also SQL Server 2005+ for parameterised TOP

0

精彩评论

暂无评论...
验证码 换一张
取 消