Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2010
    Posts
    1

    Unanswered: Rename variable in select statement?

    I'm trying to temporarily rename a variable in my select statement for sorting. For instance, "Research in Motion" is the company name, but I'd like to replace it as "BlackBerry" to sort so the output is, say:

    Apple
    BlackBerry
    Motorola
    Samsung

    Is there a command that can let me do this without replacing the actual value? Thanks.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    use a CASE expression
    Code:
    SELECT CASE WHEN company = 'Research in Motion'
                THEN 'Blackberry'
                ELSE company END AS temp_company
      FROM ...
    ORDER
        BY temp_company
    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
  •