Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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"


What I have tried:

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'
Posted
Updated 13-Jul-20 2:18am

1 solution

Try using GROUP BY: SQL GROUP BY Statement[^] - it there to "combine" rows into related items.
Be aware that you will probably need to JOIN the group results with your original table as you can only return Aggregated values with the Grouping field from GROUP BY statements.
 
Share this answer
 
Comments
Member 14726118 13-Jul-20 8:19am    
how can do it please, help
OriginalGriff 13-Jul-20 8:23am    
Follow the link, read what is says, and think about what your query is meant to do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900