sql存储过程

sql存储过程,sql,vb.net,Sql,Vb.net,问题是,我想在我的表l中获取余数的值,如果您的表已经包含一个余数字段,那么只需将其添加到INSERT语句中,如下所示: 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 @Quantit

问题是,我想在我的表l中获取余数的值,如果您的表已经包含一个余数字段,那么只需将其添加到INSERT语句中,如下所示:

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)
更好的选择可能是将表中的余数列设置为计算列。这样,即使数据不是通过存储过程添加的,您也将始终拥有该值。

一般做法是这样。然后调用方将获取该值作为参数。 比如说

    Insert Items(StoreName, ProductID, ProductName, Quantity, Defects, InsertedDate, UpdatedDate, Remainder) 
Values(@Store, @ID, @Name, @Quantity, @Defects, @IDate, @UDates, @Remainder)

我看到的是还押而不是剩余我想你是这个意思吧?我不确定我明白你的意思。你是说你不能换桌子吗?如果需要从存储过程返回@Remanders,然后,您可以使用Ralph的输出参数示例,也可以简单地使用存储过程末尾的“RETURN@Remanders”行,通过vb.net输入,因此无法输入。这就是我希望最终结果的方式…@restinutes=@Quantity-@Defectshow我按它来计算列“ALTER TABLE Items ADD restinutes AS”数量-缺陷'
create proc outputdemo(@invalue int, @outvalue int output)
as
    set @outvalue = @invalue * 2
go

declare @myvalue int
exec outputdemo 10, @myvalue output
select @myvalue