use [BandivanKat]
go
alter procedure proc1
(
@ID int,
@katnatvutyun float,
@yuxaynutyun float
)
as
declare @tari int
declare @amis int
declare @countamis int=0
if @ID in( select number from Animals where age_Group='կով' and isdeleted=0) and @ID not in (select id from katnatvutyun)
insert into katnatvutyun values (@ID,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
set @tari=YEAR(GETDATE())
set @amis=MONTH(GETDATE())
if @amis=1 begin UPDATE katnatvutyun set hunvar=(select isnull(hunvar,0) from katnatvutyun where ID=@ID)+@katnatvutyun
if (select isnull(hunvar,0) from katnatvutyun where ID=@ID)>0 set @countamis=@countamis+1
end
if @amis=2 begin UPDATE katnatvutyun set petrvar=(select isnull(petrvar,0) from katnatvutyun where ID=@ID)+@katnatvutyun
if (select isnull(petrvar,0) from katnatvutyun where ID=@ID)>0 set @countamis=@countamis+1
end
if @amis=3 begin UPDATE katnatvutyun set mart=(select isnull(mart,0) from katnatvutyun where ID=@ID)+@katnatvutyun
if (select isnull(mart,0) from katnatvutyun where ID=@ID)>0 set @countamis=@countamis+1
end
if @amis=4 begin UPDATE katnatvutyun set april=(select isnull(april,0) from katnatvutyun where ID=@ID)+@katnatvutyun
if (select isnull(april,0) from katnatvutyun where ID=@ID)>0 set @countamis=@countamis+1
end
if @amis=5 begin UPDATE katnatvutyun set majis=(select isnull(majis,0) from katnatvutyun where ID=@ID)+@katnatvutyun
if (select isnull(majis,0) from katnatvutyun where ID=@ID)>0 set @countamis=@countamis+1
end
if @amis=6 begin UPDATE katnatvutyun set hunis=(select isnull(hunis,0) from katnatvutyun where ID=@ID)+@katnatvutyun
if (select isnull(hunis,0) from katnatvutyun where ID=@ID)>0 set @countamis=@countamis+1
end
if @amis=7 begin UPDATE katnatvutyun set hulis=(select isnull(hulis,0) from katnatvutyun where ID=@ID)+@katnatvutyun
if (select isnull(hulis,0) from katnatvutyun where ID=@ID)>0 set @countamis=@countamis+1
end
if @amis=8 begin UPDATE katnatvutyun set ogostos=(select isnull(ogostos,0) from katnatvutyun where ID=@ID)+@katnatvutyun
if (select isnull(ogostos,0) from katnatvutyun where ID=@ID)>0 set @countamis=@countamis+1
end
if @amis=9 begin UPDATE katnatvutyun set september=(select isnull(september,0) from katnatvutyun where ID=@ID)+@katnatvutyun
if (select isnull(september,0) from katnatvutyun where ID=@ID)>0 set @countamis=@countamis+1
end
if @amis=10 begin UPDATE katnatvutyun set hoktember=(select isnull(hoktember,0) from katnatvutyun where ID=@ID)+@katnatvutyun
if (select isnull(hoktember,0) from katnatvutyun where ID=@ID)>0 set @countamis=@countamis+1
end
if @amis=11 begin UPDATE katnatvutyun set noyember=(select isnull(noyember,0) from katnatvutyun where ID=@ID)+@katnatvutyun
if (select isnull(noyember,0) from katnatvutyun where ID=@ID)>0 set @countamis=@countamis+1
end
if @amis=12 begin UPDATE katnatvutyun set dektember=(select isnull(dektember,0) from katnatvutyun where ID=@ID)+@katnatvutyun
if (select isnull(dektember,0) from katnatvutyun where ID=@ID)>0 set @countamis=@countamis+1
end
update katnatvutyun set summilk=(isnull(hunvar,0)+ isnull(petrvar,0)+isnull(mart,0)+isnull(majis,0)+isnull(hunis,0)+isnull(hulis,0)+isnull(ogostos,0)+isnull(september,0)+isnull(hoktember,0)+isnull(noyember,0)+isnull(dektember,0)) where ID=@ID
update katnatvutyun set avgmilk=summilk/@countamis where ID=@ID
if @yuxaynutyun <>'' UPDATE katnatvutyun set yuxaynutyun = @yuxaynutyun
go
У меня вот такой код в БД но не понимаю почему не работает возвращает целочисленное значение место того что бы записать данные в таблицу
Таблица вот такая
create table katnatvutyun
(
ID integer primary key ,
hunvar float,
petrvar float,
mart float,
april float,
majis float,
hunis float,
hulis float,
ogostos float,
september float,
hoktember float,
noyember float,
dektember float,
summilk float,
avgmilk float
)
первые 12 столбцы это название месяцев,в каждом месяце вводится одно значение процедура определяет какой месяц и значение записывает в нужном столбце,в summilk считывается общая сумма,а avgmilk определяет сколько столбцов было записан значения и считывает для них средное значение,процедура принимает три параметра
1. номер животного для которого должно сделать запись
2. значение на месяца (одно число например 50)
3. просто характеризующая число
третий параметр записывается в этом столбце
alter table katnatvutyun ADD yuxaynutyun float