Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2010
    Location
    Atlanta, GA
    Posts
    211
    Provided Answers: 1

    Question Unanswered: Is there a quicker/more efficient way to change result names besides CASE?

    Example:

    Select StoreId from tblStores
    S1
    S2
    S3
    S4

    I want to display a more friendly name. I have been using a case statement:

    select case
    WHEN storeId = 'S1' THEN 'NY Store'
    WHEN storeId = 'S2' THEN 'CA Store'
    ...
    end AS StoreName

    If I am doing a simple 1:1 mapping like that, is there a better way than using a case statement (without creating/modifying tables)?

  2. #2
    Join Date
    Aug 2012
    Posts
    30
    nope. the best way is to create a mapping table so that its scalable and more maintainable

    if you cant create table, there's no way unless you're using SQL 2012 in whic case you can use series of IIF() for getting the result

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by clawlan View Post
    ...is there a better way than using a case statement (without creating/modifying tables)?
    are you trying to say that the tblStores table does not have a StoreName column, and you can't fix it so that it does?

    dude, my condolences

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •