create PROC insert_Items(@Store varchar(20),@ID varchar(20),@Name varchar(20),@IDate varchar(11))
As
Declare @UDates varchar(11),
Declare @Quantity int,
Declare @Defects int
Select @Quantity From inserted
Select @Defects From Inserted
set @UDates = getdate(),
@Remanders = @Defects - @Quantity
Insert Items(StoreName,ProductID,ProductName,Quantity,Defects,InsertedDate,UpdatedDate)
Values(@Store,@ID,@Name,@Quantity,@Defects,@IDate,@UDates)问题是我想要得到表l中余数的值。
发布于 2011-04-29 22:08:56
如果您的表已经包含一个剩余字段,则只需将其添加到INSERT语句中,如下所示:
Insert Items(StoreName, ProductID, ProductName, Quantity, Defects, InsertedDate, UpdatedDate, Remainder)
Values(@Store, @ID, @Name, @Quantity, @Defects, @IDate, @UDates, @Remainder)更好的选择可能是使表中的Remainder列成为计算列。这样,即使数据不是通过您的存储过程添加的,您也将始终拥有该值。
发布于 2011-04-29 22:08:57
一般的做法是declare an OUTPUT parameter for the procedure。然后,调用者将获得该值作为参数。
例如
create proc outputdemo(@invalue int, @outvalue int output)
as
set @outvalue = @invalue * 2
go
declare @myvalue int
exec outputdemo 10, @myvalue output
select @myvaluehttps://stackoverflow.com/questions/5833032
复制相似问题