我创建了一个存储过程。如果值小于 100,它将返回 0,否则将返回 1。它在添加新记录的情况下工作良好,但在编辑现有记录的情况下,它是对所有以前的记录求和,因此每次值都大于 100。我的 sp是:
ALTER PROCEDURE [dbo].[spDescriptionWeightIsLessThanHundred]
-- Add the parameters for the stored procedure here
@ExistingComponentId int,
@WeightToAdd float
AS
BEGIN
SET NOCOUNT ON;
declare @existingWeightOfComponentGuideline float
select @existingWeightOfComponentGuideline = SUM(tcgd.weight)
from [TemplateGuidelineDescription] tcgd
where tcgd.[TemplateGuidelineId] = @ExistingComponentId
declare @totalWeight float
set @totalWeight = @existingWeightOfComponentGuideline + @WeightToAdd
if @totalWeight <= 100
begin
select 0
end
else
begin
select 1
end
END
请在代码中帮助我。我想编辑我的价值观。谢谢