jeudi 16 avril 2020

MSSQL IF or CASE statement with sum

I have a short questions on if and case statements in mssql:

This is my code:

(SELECT IsNULL(SUM(t.Column1),0)
              FROM test t
             WHERE t.Column1 = "Test"
               AND t.Column2 = "Test2") AS Result

Now I want a statement like:

SELECT IsNULL(SUM(t.Column1),0) Result1
CASE WHEN t.Column3 = '1' THEN Result1 / 1
ELSE Result1
END AS Test2
FROM test t
WHERE t.Column1 = "Test"
AND t.Column2 = "Test2") AS Result

Any ideas how i can solve this problem? Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire