Chris Miller Blog

RocketScientist's Miscellaneous Ramblings

Someone might not understand how CASE works….

    case when StatusFlag = 'LWCA' and TransactionType <> 'W' then 'Layw Cancel'
        ELSE
    case when StatusFlag = 'LWCA' and TransactionType = 'W' then 'Warranty Cancel'
        ELSE
    case when StatusFlag = 'WAPK' then 'Warranty Pickup'
        ELSE
    case when StatusFlag = 'LWSE' and TransactionType <> 'W' then 'Layaway'
        ELSE
    case when StatusFlag = 'LWSE' and TransactionType = 'W' then 'Warranty Setup'
        ELSE
    case when StatusFlag = 'SALE' and isnull(HV.QTY,0) > 0 and layawaynumber is null then 'Sale'
        ELSE
    case when StatusFlag = 'SALE' and isnull(HV.QTY,0) > 0 and NOT layawaynumber is null then 'Lwy Pickup'
        ELSE
    case when StatusFlag = 'SALE' and isnull(HV.QTY,0) <= 0 then 'Return'
    End End End End End End End End,

Legacy Comments


Brian Tkatch
2009-05-05
re: Someone might not understand how CASE works....
Maybe they are aiming for the Obfuscated C(equal) award?

Pollus Brodeur
2009-05-07
re: Someone might not understand how CASE works....
You should provide the correct way to write it so people may compare:

case
when StatusFlag = 'LWCA' and TransactionType <> 'W' then 'Layw Cancel'
when StatusFlag = 'LWCA' and TransactionType = 'W' then 'Warranty Cancel'
when StatusFlag = 'WAPK' then 'Warranty Pickup'
when StatusFlag = 'LWSE' and TransactionType <> 'W' then 'Layaway'
when StatusFlag = 'LWSE' and TransactionType = 'W' then 'Warranty Setup'
when StatusFlag = 'SALE' and isnull(HV.QTY,0) > 0 and layawaynumber is null then 'Sale'
when StatusFlag = 'SALE' and isnull(HV.QTY,0) > 0 and NOT layawaynumber is null then 'Lwy Pickup'
when StatusFlag = 'SALE' and isnull(HV.QTY,0) <= 0 then 'Return'
End,