必须在创建存储过程时声明标量变量

时间:2014-03-15 16:03:41

标签: sql-server stored-procedures

我正在创建第一次存储过程,但我不知道为什么会显示错误。我还有很多其他的帖子,但我不明白是否有人可以告诉我这里做错了什么。

存储过程:

SET ANSI_NULLS ON
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[DeleteOrganization]
    @ORG_ID bigint
AS
BEGIN
    SET NOCOUNT ON;

    delete from Organizations where ORG_ID=@ORGID
    delete from Institutes where INS_FK_ORGID=@ORGID
    delete from Branches where BRN_ID=@ORGID
END

1 个答案:

答案 0 :(得分:2)

变量声明为@ORG_ID bigint,带有下划线,但您引用它时没有下划线:@ORGID。选择一个并持续使用它。

这应该有效:

ALTER PROCEDURE [dbo].[DeleteOrganization]
@ORGID bigint
AS
BEGIN
    SET NOCOUNT ON;    
    DELETE FROM Organizations WHERE ORG_ID = @ORGID
    DELETE FROM Institutes WHERE INS_FK_ORGID = @ORGID
    DELETE FROM Branches WHERE BRN_ID = @ORGID
END