这给我@ID
和@Name
Must 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
答案 0 :(得分: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是因为我的测试表上没有标识