SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    2 Thread(s)

    Alias in CASE possible?

    Hi is there some way that output can have different aliases for the THEN or ELSE of the CASE?

    Code:
    SELECT
      CASE WHEN prg.program_name LIKE '%Family Emergency%' 
            THEN l2prg.registration_number as 'Registrant Number' 
            ELSE l2prg.registration_number as 'Program Number' 
       END
    This does not work and I have tried various bracketing that did not work. It is not a huge deal if this can't be done because it easy enough to do this programatically but it would be nice to know if there is some way to do this?

    Steve
    ictus==""

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    you're on the right track but barking up the wrong tree


    offtopic: anyone familiar with the classic book "Go Dog Go"?



    what you want is something like this --
    Code:
    SELECT l2prg.registration_number
         , CASE WHEN prg.program_name LIKE '%Family Emergency%' 
                THEN 'Registrant Number' 
                ELSE 'Program Number' 
            END AS number_type
    although in my experience a yellow flag should go up whenever the same column sometimes means one thing and sometimes another
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by r937 View Post
    you're on the right track but barking up the wrong tree

    offtopic: anyone familiar with the classic book "Go Dog Go"?
    That is a fantastic book that my kids loved when they were little!


    Quote Originally Posted by r937 View Post
    what you want is something like this --
    Code:
    SELECT l2prg.registration_number
         , CASE WHEN prg.program_name LIKE '%Family Emergency%' 
                THEN 'Registrant Number' 
                ELSE 'Program Number' 
            END AS number_type
    Yes that divergent thinking thing coming into play again. Thank you.

    Quote Originally Posted by r937 View Post
    although in my experience a yellow flag should go up whenever the same column sometimes means one thing and sometimes another
    The customer for this application has a primary program that they want to display and input in separate fields than the other programs they have; although All these programs have a unique registrant number, program name and registration date.

    If I was to break this into separate tables then I would have a complete duplicate structure to the programs table. Does it make sense to break these apart or does this way of doing things - in this case - make sense?
    ictus==""

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by ServerStorm View Post
    Does it make sense to break these apart ...
    no, i do not like that hat

    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    2 Thread(s)
    Ok, already rolled ahead keeping as is...

    off topic: you have quite the plethora of classic book quotes because the 'no, i do not like that hat' is CAT in the HAT...NICE
    Thank you.
    ictus==""

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by http://ejournals.library.ualberta.ca/index.php/deakinreview/article/view/10841
    Aside from being a great tool for teaching, this book is also a humorous tale for the reader. Several times throughout the book, one dog wearing a simple hat asks another dog whether or not he likes it. He bluntly replies, I do not like that hat, and the two part ways. This happens several more times with several more plain hats, and each time the dog replies I do not like that hat. At the large dog party at the end of the book, the first dog is wearing an over-the-top, outlandish party hat that is borderline ridiculous; it is at this time that the second dog agrees that it is a great hat, and the two ride off into the sunset together.
    just thought you should know which book i was quoting

    now we can meander off into the sunset at last...
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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