IF..ELSE clause in SQL Server is used for decision making. You can use it to run a set of statements based on certain conditions. The following are the examples on how to use it effectively for various purposes.
declare @status bit
set @status=1
if @status=0
print 'The event is closed'
else
print 'The event is started'
if @status=0
Begin
print 'use id column in the where clause'
select * from #t where id=2
End
else
Begin
print 'use names column in the where clause'
select * from #t where names='Suresh'
End
Read more: Beyond Relational
declare @status bit
set @status=1
if @status=0
print 'The event is closed'
else
print 'The event is started'
if @status=0
Begin
print 'use id column in the where clause'
select * from #t where id=2
End
else
Begin
print 'use names column in the where clause'
select * from #t where names='Suresh'
End
Read more: Beyond Relational