user3636272
user3636272

Reputation: 71

MS-Access iif statement convert to T-SQL

Trying to convert access iif statement

IIf(FD.[Sales_Value] = 0, 'Component',
    (IIf(FD.[Lines] = 0,    
        IIf(FD.[Sales_Value] = FD.[Gross_Contribution],
            'Composite', 'N'),
        'N')
    )
) AS Composite,

I have this at the moment but it doesn't like it

CASE WHEN FD.[Sales_Value] = 0 THEN 'Component'
ELSE CASE WHEN FD.[Lines] = 0 THEN
        CASE WHEN FD.[Sales_Value] = FD.[Gross_Contribution] THEN 'Composite' ELSE 'N' --END
        ELSE
            'N'
        END 
END
    AS Composite

Upvotes: 0

Views: 205

Answers (1)

HoneyBadger
HoneyBadger

Reputation: 15150

This should work, much better readable:

CASE 
    WHEN FD.[Sales_Value] = 0 THEN 'Component'
    WHEN FD.[Lines] = 0 AND FD.[Sales_Value] = FD.[Gross_Contribution] 
       THEN 'Composite' 
    ELSE 'N'
END
    AS Composite

Upvotes: 2

Related Questions