Click here to Skip to main content
15,904,155 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends ,
I have three table Countdown, Walk, Bon de reception
The Id_marche is a foreign key in the countdown table and
The Receipt table contains the Id_marche
I want to insert in recordings in the counting table which contains Amount TTC so to calculate Amount TTC = TVA* Amount HT
I have the TVA AND the Amount HT in the voucher table of reception
I could not create a request to insert and calculate the amount TTC
I do not know is what I described well my condition but hey I will screenshot the three table and you will see the relationship between them
And thank you for you in advance

What I have tried:

SQL
insert into decompte 
(Id_marche,Num_decompte,Date_etablissement,Flag_dernier,Montant_ttc,Retenue_garantie,Penalite_retard,Revision_prix,
Autres_retenues,Retenue_source,User_create,Date_create)
values
((select TOP 1 Id_marche from marche where Num_marche='"+textBox1.Text+"'),
'"+textBox3.Text+"','"+dateTimePicker1.Value.Date+"','"+cocher+"',
(select TOP 1 marche.Id_marche from marche , bon_reception_marche br ,decompte where br.Id_marche=marche.Id_marche and decompte.Montant_ttc=br.Montant*br.TVA),
"+Convert.ToDouble(textBox4.Text)+","+Convert.ToDouble(textBox4.Text)+","+Convert.ToDouble(textBox4.Text)+",
"+Convert.ToDouble(textBox4.Text)+","+Convert.ToDouble(textBox4.Text)+","+Convert.ToDouble(textBox4.Text)+",
'"+values.username+"',DateTime.Now.Date)
Posted
Updated 21-Mar-17 23:04pm
v2
Comments
[no name] 21-Mar-17 19:56pm    
If you don't listen to what people tell you, we end up just wasting our time.

1 solution

DECLARE @Id_marche int = 8;
INSERT INTO decompte (Id_marche, Montant_ttc)
SELECT
marche.Id_marche
,SUM(b.Montant) * SUM(b.TVA) as TTC
FROM marche WITH (NOLOCK)
LEFT JOIN bon_reception_marche b WITH (NOLOCK)
ON marche.Id_marche = brm.Id_marche
WHERE marche.Id_marche = @Id_marche
GROUP BY marche.Id_marche
 
Share this answer
 

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