Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2002
    Location
    Montreal, Canada
    Posts
    44

    Unanswered: Is there an equivalent to an MSAccess IIF statement when creating Store Procs

    I'm creating a stored proc and need to use some sort of IF or IIF statement. Is theresome sort of equivalent statement i can use?

  2. #2
    Join Date
    Feb 2002
    Location
    Houston, TX
    Posts
    809
    T-SQL supports an IF and CASE statment. you can read up on both in Books Online.

    IF...ELSE
    Imposes conditions on the execution of a Transact-SQL statement. The Transact-SQL statement following an IF keyword and its condition is executed if the condition is satisfied (when the Boolean expression returns TRUE). The optional ELSE keyword introduces an alternate Transact-SQL statement that is executed when the IF condition is not satisfied (when the Boolean expression returns FALSE).

    Syntax
    IF Boolean_expression
    { sql_statement | statement_block }
    [ ELSE
    { sql_statement | statement_block } ]


    CASE
    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
    ]
    END

    Searched CASE function:

    CASE
    WHEN Boolean_expression THEN result_expression
    [ ...n ]
    [
    ELSE else_result_expression
    ]
    END
    Paul Young
    (Knowledge is power! Get some!)

  3. #3
    Join Date
    Feb 2003
    Posts
    27
    IF(<CHECK CONDITION>)
    BEGIN
    <CODE>
    END
    ELSE
    BEGIN
    < CODE>
    END

  4. #4
    Join Date
    Feb 2003
    Location
    Montreal, Canada
    Posts
    117

    Re: Is there an equivalent to an MSAccess IIF statement when creating Store Procs

    IIF doesn't exists in SQL but you can always use the old fashion way:

    IF <your_condition>
    BEGIN
    :
    :
    END
    ELSE
    BEGIN
    :
    :
    END



    Originally posted by Sammy_S
    I'm creating a stored proc and need to use some sort of IF or IIF statement. Is theresome sort of equivalent statement i can use?
    Steve

Posting Permissions

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