给你一个例子:
USE pubs
SELECT
   CASE type
      WHEN 'popular_comp' THEN 'Popular Computing'
      WHEN 'mod_cook' THEN 'Modern Cooking'
      WHEN 'business' THEN 'Business'
      WHEN 'psychology' THEN 'Psychology'
      WHEN 'trad_cook' THEN 'Traditional Cooking'
      ELSE 'Not yet categorized'
   END AS Category, 
CONVERT(varchar(30), title) AS "Shortened Title", 
price AS Price
FROM titles
WHERE price IS NOT NULL
ORDER BY 1

解决方案 »

  1.   

    CASE (T-SQL)
    Evaluates a list of conditions and returns one of multiple possible result expressions. CASE has two formats: The simple CASE function compares an expression to a set of simple expressions to determine the result. 
    The searched CASE function evaluates a set of Boolean expressions to determine the result. 
    Both formats support an optional ELSE argument. Syntax
    Simple CASE function:CASE input_expression
        WHEN when_expression THEN result_expression
            [...n]
        [
            ELSE else_result_expression
        ]
    ENDSearched CASE function:CASE
        WHEN Boolean_expression THEN result_expression
            [...n]
        [
            ELSE else_result_expression
        ]
    ENDArguments
    input_expression 
    Is the expression that is evaluated when using the simple CASE format. input_expression is any valid Microsoft® SQL Server™ expression. 
    WHEN when_expression 
    Is a simple expression to which input_expression is compared when using the simple CASE format. when_expression is any valid SQL Server expression. The data types of input_expression and each when_expression must be the same or must be an implicit conversion. 

    Is a placeholder indicating that multiple WHEN when_expression THEN result_expression clauses, or multiple WHEN Boolean_expression THEN result_expression clauses can be used. 
    THEN result_expression 
    Is the expression that is returned when input_expression equals when_expression evaluates to TRUE, or Boolean_expression evaluates to TRUE. result expression is any valid SQL Server expression. 
    ELSE else_result_expression 
    Is the expression that is returned if no comparison operation evaluates to TRUE. If this argument is omitted and no comparison operation evaluates to TRUE, CASE returns NULL. else_result_expression is any valid SQL Server expression. The data types of else_result_expression and any result_expression must be the same or must be an implicit conversion. 
    WHEN Boolean_expression 
    Is the Boolean expression that is evaluated when using the searched CASE format. Boolean_expression is any valid Boolean expression. 
      

  2.   

    同上意见,中文版的SQL SERVER 2000内有详尽的中文说明书
      

  3.   

    我问的是控制结构。比方说:
    if @aa=1
    exec ..........
    else
    if @aa=2
    exec ......
    else
    if @aa=3
    exec........
    请教!!