There is a request:

select @a=sum(количество ) from Заявка where Статус='В пути' AND Заявка.Наименование_детали=@с group by Наименование_детали 

It returns null, can it be done so that it returns zero? Because of this, the update does not work

 update Ведомость_материалов set Чистая_потребность=@b-Колличество_на_складе-@a where Ведомость_материалов.Материал=@q 

because null = null

  • one
    ...=coalesce(sum(количество), 0)... - Igor
  • one
    ... or ... ISNULL(SUM(количество), 0) ... By the way, why do you have a group by initial request? - Yaant

1 answer 1

well, or through CASE

... = case when sum (number) is null then 0 else sum (number) end