Welcome! Log In Create A New Profile

Advanced

Question regrading SQL query in WINDEV

Posted by JON LAU 
JON LAU
Question regrading SQL query in WINDEV
March 06, 2023 12:37PM
1) The following SQL statement is working
SELECT
SUM(sales.TotalAmount) AS the_sum_Total
FROM
sales
WHERE
LEFT(sales.InvDate ,6) = {paramMonth}

2) But the moment i need to deduct the discount amount from Total Amount, the_sum_total will return NULL
SELECT
SUM((sales.TotalAmount - sales.DiscountAmount)) AS the_sum_Total
FROM
sales
WHERE
LEFT(sales.InvDate ,6) = {paramMonth}


Is there a bug in the SQL query where i cannot deduct within the SUM?

Regards,

Jon Lau
Re: Question regrading SQL query in WINDEV
March 06, 2023 02:47PM
Hey Jon,

I'm not at my dev machine so can't confirm, but try putting "- sales.DiscountAmount" outside the sum function brackets.

Regards,
Darren.
JON LAU
Re: Question regrading SQL query in WINDEV
March 07, 2023 08:20AM
Hi Darren,


Do you mean :-

SELECT
SUM(sales.TotalAmount) - SUM(sales.DiscountAmount) AS the_sum_Total
FROM
sales
WHERE
LEFT(sales.InvDate ,6) = {paramMonth}

Regards,

Jon Lau
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: