case statement in sqlserver 2005

  • Hi experts,

    CASE WHEN ORDER.CATEGORY_CODE = 'RETURN' THEN

    (NVL(ORDER.ORDERED_QUANTITY,0) - NVL(ORDER.SHIPPED_QUANTITY,0) ) *-1

    ELSE

    (NVL(ORDER.ORDERED_QUANTITY,0) - NVL(ORDER.SHIPPED_QUANTITY,0) )

    END Qty,

    It is my oracle case statement,i have to write same functionality in sqlserver 2005,how can i write? please help on this

    Thanks

    venki

  • The Case looks ok, but NVL is not a SQL function. What does it do?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • In Place of NVL just replace with COALESCE

    CASE WHEN ORDER.CATEGORY_CODE = 'RETURN' THEN

    (COALESCE(ORDER.ORDERED_QUANTITY,0) - COALESCE(ORDER.SHIPPED_QUANTITY,0) ) *-1

    ELSE

    (COALESCE(ORDER.ORDERED_QUANTITY,0) - COALESCE(ORDER.SHIPPED_QUANTITY,0) )

    END Qty,

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply