Search This Blog

IF Else Condition in SQL

IF Else Condition in SQL 

The IF Else condition in sql allows us to control the flow of our sql code or query.
For example the below if else condition shows that if current date is greater then 15 of the month then it will show
Fee pending please pay the fees
else It will show 'you have paid your fees'


if day(getdate())>15
print 'Your fees date is over please pay the Pending fees'
else
print 'you have paid your fees'

Output--as today date is 16 december greater then 15
Your fees date is over please pay the Pending fees

IF you want more condition to be added you can you else if statetement or case statement.

Syntax else if

IF condition1..
result1
else if  condition2...
result2
else condition2...
result

Syntax case 
Case when condition1 then result1
Case when condition2 then result 2
else result3 end

No comments:

Post a Comment