1

这给了我一个错误@ID@NameMust declare the scalar variable,但我不明白为什么它是一个参数。我在这里做错了什么?

  CREATE PROCEDURE [dbo].[Ins_eProductFull]
    @Name nvarchar(400)
    ,@ID int

    AS
  BEGIN

    DECLARE @ID2 int

    SET NOCOUNT ON;

    INSERT INTO Table (Name) VALUES (@Name)

    SET @ID2 = SCOPE_IDENTITY()

    EXEC dbo.StoredProc1 
      @ID = @ID, 
      @Name = @Name, 
      @ID2 = @ID2

  END
  GO
4

1 回答 1

3

我在您的代码中看到的唯一问题是第一个不应该存在的逗号。除此之外一切正常

编辑:

对于否决它的人,请亲自查看:

create table Table1(Name varchar(50))

Create PROCEDURE [dbo].[Ins_eProductFull]
@Name nvarchar(400),
@ID int
AS
BEGIN
    DECLARE @ID2 int

    SET NOCOUNT ON;

    INSERT INTO Table1 (Name) VALUES (@Name)

    SET @ID2 = SCOPE_IDENTITY()

    EXEC dbo.StoredProc1 
      @ID = @ID, 
      @Name = @Name, 
      @ID2 = @ID2

END
GO

CREATE  procedure dbo.StoredProc1 
@ID int,
@Name varchar(50),
@ID2 int
as 
begin
    select @ID,@Name,@id2
end


exec [Ins_eProductFull] 'a',1

结果:

1   a   NULL

NULL是因为我的测试表上没有身份

于 2012-04-23T15:30:36.247 回答