This is a mirror of official site: http://jasper-net.blogspot.com/

SQL Server - Writing IF-ELSE code in TSQL

| Monday, August 16, 2010
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

Posted via email from .NET Info

0 comments: