Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2002
    Posts
    37

    Unanswered: Case / Switch function help

    Starting to play around with SQL server at work and this is my question:

    In the query design mode in access I can make one of the fields an expression that is driven by a built-in switch function.
    i.e. Switch([CategoryName] Like "Beverage","Drink",[CategoryName] Like "Cheese","Dairy")
    This results in the additional column field I created to display "Drink" for each record that has the CategoryName = "Beverage", and "Dairy" for "Cheese".

    Can I do something like this in SQL server in the view designer itself, or do I need to make a user defined function and call it?

    Thanks in advance for any help.

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Use the CASE statement in SQL Server.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Nov 2002
    Posts
    37
    Can I do this in the view design mode or do I need to make a user defined function?
    Any sample code would be really appreciated.

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    CASE WHEN [CategoryName] = 'Beverage' THEN 'Drink'
    WHEN [CategoryName] = 'Cheese' THEN 'Dairy'
    ELSE 'Unknown'
    END AS DerivedColumnName
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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