Помогите обновить мой SQL запрос
In the case of whether the date exists or a valid date: the text calculates the period between two dates per month and days and multiplies it by the amount of compensation in the number of person who benefit from it Example: Number of person 2, compensation amount 4000 DZD, the period between 01/04/2020 to 2/18/2020 (1 month and 14 days) (((4000 DZD * 14 days) / 30) + (4000 DZD * 1 month)) * 2 Number of people = 11733.33 DZD problem in query If the file has one compensation, it will calculate, and if the file has a set of compensation, an error is displayed Msg 512, Level 16, State 1, Line 4 Subquery returned more than 1 value. This is not permitted when the subquery follows =,! =, <, <=,>,> = Or when the subquery is used as an expression. Msg 512, Level 16, State 1, Line 14 Subquery returned more than 1 value. This is not permitted when the subquery follows =,! =, <, <=,>,> = Or when the subquery is used as an expression. the question: How can I show all the compensation and the corresponding accounts for each file separately so that if I change the file number for example "20/0003"
Что я уже пробовал:
declare @days int declare @month int declare @Total dec(18,2) if (select isdate(date_debut1) from Indemnite where id_aff='20/0002') =1 begin select @month = DateDiff(month, date_debut1, date_fin1) from indemnite select @days = DateDiff(day, DateAdd(month, DateDiff(month, date_debut1, date_fin1), date_debut1), date_fin1) from indemnite where id_aff='20/0002' if @days < 0 begin select @month=@month-1 from indemnite select @days = DateDiff(day, DateAdd(month, @month, date_debut1), date_fin1) from indemnite where id_aff='20/0002' end select @month=@month *1% 12 select @Total =(((montant_dette1 * @days)/30)+(montant_dette1 *@month))* n_personne1 from Indemnite where id_aff='20/0002' end if (select isdate(date_debut1)from Indemnite where id_aff='20/0002') =0 begin select @Total =(montant_dette1 * n_personne1) from Indemnite where id_aff='20/0002' end select Indemnite1, n_personne1, date_debut1, date_fin1, montant_dette1,@Total as Total FROM Indemnite where id_aff='20/0002'