How to write switch case scenario in sp

  • Dear All,

     

    I am using Sql server 2005

     

    Let me explain you scenario.

     

    I would like to know Is it possible to use switch case(like we do in C#) in stored procedure.if not what if alternative of that. Because based on input parameter I would like to perform different action  

     

    Please guide me or give me some useful link.

    Thanks  

     

     

  • yes its possible use

    CASE ...

    WHEN x THEN ....

    END

    look it up in BOL


    Everything you can imagine is real.

  • A case statement in SQL can only be used within a select/update statement. It can't be used for control flow in the procedure. For the latter, use IF statements.

    The form of a case statement in SQL is

    SELECT CASE Field1 When 1 THEN 'One' When 2 THEN 'Couple' ELSE 'Many' END As HowMany

    FROM tbl

    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
  • it might be helpful for you to post your code and then we can take it from there.


    Everything you can imagine is real.

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

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