开发者

T-SQL How to run procedure recursively?

in my procedure, I try to run itself recursively when some conditions appear

(I simplified the code just to find out how to do the recursion)

Firstly I created the procedure with commented the BEGIN..END body, and then:

alter PROCEDURE [dbo].[insert_new_customer_task]
     @TaskTypeID decimal,
     @TaskName nvarchar(1000),
     @IDCsrUser decimal,
     @TaskStatusID decimal,
     @ActualDatePar开发者_运维知识库am datetime,
     @isNextDate bit
AS
BEGIN   
      [dbo].[insert_new_customer_task](@TaskTypeID,@TaskName,@IDCsrUser,@TaskStatusID,@ActualDateParam,1)
END
GO

but I see an error inside BEGIN..END Incorrect syntax near 'dbo'. So how to solve it ?


Add EXEC command and remove the parentheses around parameters:

EXEC [dbo].[insert_new_customer_task]
     @TaskTypeID, @TaskName,@IDCsrUser,@TaskStatusID,@ActualDateParam,1


I think you need EXEC and no brackets on the parameters, i.e.

EXEC [dbo].[insert_new_customer_task] @TaskTypeID,@TaskName,
     @IDCsrUser,@TaskStatusID,@ActualDateParam,1


alter PROCEDURE [dbo].[insert_new_customer_task](
     @TaskTypeID decimal,
     @TaskName nvarchar(1000),
     @IDCsrUser decimal,
     @TaskStatusID decimal,
     @ActualDateParam datetime,
     @isNextDate bit)
AS
BEGIN   
      EXEC [dbo].[insert_new_customer_task] @TaskTypeID,@TaskName,@IDCsrUser,@TaskStatusID,@ActualDateParam,1
END
GO

you need parenthesis around procedure definition, not in body where you call it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜