Friday 2 August 2013

If else condition in Sql

If else conditions are used to test  conditions  ,It is used in stored procedure(SP),Trigger etc
The execution of if else statement is same as C or C++ Language .

Syntax:
IF (Condition)
  BEGIN
     Sql statements 1
  ENd

ELSe

  BEGIN
Sql statements 2
  END


Explanation :
If condition is true execute Sql statements1 otherwise execute Sql statements2 .

Example:
IF (10<2)
  BEGIN
     select name from account
  ENd
ELSe
  BEGIN
   select * from account
  END
Result:
The above example execute  Sql statements 2 ie,  select * from account

0 comments:

Post a Comment