CASE for 500 cases?

  • Hi,

    I have some custom mapping to apply which has ~500 cases, does it worth to code it with CASE or probably I can do something more nicer, like use table or something else.

    This is old code that I'm borrowing for my purpose.

    Tx

    Mario

  • mario17 (10/22/2013)


    Hi,

    I have some custom mapping to apply which has ~500 cases, does it worth to code it with CASE or probably I can do something more nicer, like use table or something else.

    This is old code that I'm borrowing for my purpose.

    Tx

    Mario

    Given that there are not many details posted here you are not likely to find many answers.

    500 case expressions sounds like there is something majorly wrong going on here.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • mario17 (10/22/2013)


    Hi,

    I have some custom mapping to apply which has ~500 cases, does it worth to code it with CASE or probably I can do something more nicer, like use table or something else.

    This is old code that I'm borrowing for my purpose.

    Tx

    Mario

    I would use a lookup table rather than coding a gigantic CASE statement.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Thanks, Sean and Koen.

    It's pretty strighforward:

    case col1

    when '001' then 'alpha'

    when '002' then 'bravo'

    ....

    when '500' then 'zulu500'

    else 'unkknown'

    So I'll go with lookup table, to make it readable. + I just found out that I'll need to add 'second level' mapping so table will work fine.

    case col2

    when 'alpha' and col3=123 then 'alpha123'

    when 'alpha' and col3=567 then 'alpha567'

    etc..

    Tx much

    \M

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

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