简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM