SQL Nested CASE Statement

I am trying to update the following query segment in a Sales Analysis cube. I’m not deeply familiar with SQL.

The first CASE statement works as it should – returns a negative when OINV.Canceled = ‘Y’.

CASE OINV.Canceled WHEN 'Y' THEN - INV1.LineTotal 
ELSE INV1.LineTotal END AS LineTotal, 
CASE INV1.StockSum WHEN 0 THEN INV1.LineTotal 
ELSE INV1.StockSum END AS SaleValue, INV1.GrssProfit

What I’m trying to achieve is for the second CASE statement to also return a negative value (SaleValue) when OINV.Canceled = ‘Y’. I think I need to nest a CASE statement here but I’m not sure.


Source: sql

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.