Skip to main content

Posts

Showing posts from February, 2007

T-SQL IF...ELSE Statement

You must have been in a situation wherein you have to select between this or that, right or left depending on your present situation. If you were to stimulate this kind of situation in SQL, you need to use the IF-ELSE statement. IF - ELSE is the most commonly used Transact SQL command, that executes a statement depending on the condition. If the condition for IF statement is True, the statements inside the 'Begin-End' loop of 'IF' statement will be executed. If the condition for IF statement is False, the statements inside the 'Begin-End' loop of 'ELSE' statement will be executed. Thus, depending on which condition is true, statement or block of statements are executed The basic Syntax for IF..ELSE is: IF ( Boolean_expression )    BEGIN    'Sql Statement Block'    END ELSE    BEGIN    'Sql Statement Block'    END Simple If..Else Statement example IF (x>y)    BEGIN    SELECT 'If x is greater than y, this statement