A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Hi @kasim mohamed
Check this:
SELECT TDate
,SUM(CASE WHEN TType=1 THEN Net
WHEN TType=2 AND SType<>'22' AND SCode<>'XYZ' THEN Net
WHEN TType=3 AND SType<>'22' THEN Net ELSE 0 END) AS A
,SUM(CASE WHEN TType IN(2,3) AND SType = '22' THEN Net ELSE 0 END) AS B
,SUM(CASE WHEN TType =3 AND SType <> '22' AND SCode ='XYZ' THEN Net ELSE 0 END) AS C
FROM ##Main M JOIN ##Sub S ON M.ID=S.ID
GROUP BY TDate
Output:
And I found that the column_A value on 2022-5-03 in the output is not the same as your result table, please check it. If i understand your logic right, it should be 150, not 100.
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.