The syntax of the IF...ELSE statement : IF « Transact SQL « SQL Server / T-SQL Tutorial






IF A=B
   Statement when True
ELSE
   Statement when False



To batch statements together within an IF ELSE, we must surround the code with a BEGINEND block.
An example of how the code would look follows:
IF A=B
   BEGIN
      Statement when True
      Another statement when True
      Yet Another True statement
   END
ELSE
   False statement


6> IF 12.0 > 10E
7>   PRINT 'Bigger'
8> ELSE
9>   PRINT 'Smaller';
10> GO
Bigger








20.7.IF
20.7.1.The syntax of the IF...ELSE statement
20.7.2.Using an Expression with an Explicit Unknown Value
20.7.3.Using an Expression with an Unknown Value Returned from One of the Participating Simple Logical Expressions
20.7.4.Short circuit aborts any further processing of a logical expression as soon as its result can be determined.
20.7.5.IF (@au_id IS NULL)
20.7.6.IF EXISTS
20.7.7.Use function returned value
20.7.8.IF (SELECT ID FROM inserted) like '99[0-9][0-9]'
20.7.9.IF (SELECT COUNT(*) FROM inserted) > 1
20.7.10.If statement with aggregate function
20.7.11.Use if and like to check a pattern
20.7.12.Implementing the ELSE Statement In Our Sproc
20.7.13.A script that tests for outstanding Billings with an IF statement
20.7.14.uses an IF...ELSE statement