If else if else condition statement in sql server

If else if else condition statement

Syntax of if condition
----------------------

if(condition)
 Begin
  -stmts
 End
Else if
 Begin
 -stmts
 End
-----< multiple else if blocks if rquired ------------->
 Else
 Begin
 -stmts
 End


Note : if the block contains only a single statement begin or end are optional for the block.

 
Declare @Weekday int,EmpNo int =1005

Select @weekday =Datepart(dw,Hiredate) from Emp where EmpNo=@EmpNo

if @weekday=1

 print 'Sunday'

else if @weekday=2

 print 'Monday'

else if @weekday=3

 print 'Tuesday'

else if @weekday=4

 print 'Wedensday'

else if @weekday=5

 print 'Thursday'

else if @weekday=6

 print 'Firday'

else 
 print 'Saturday'

About Author: author 4 + years of Information Technology experience in understanding and analyzing the software and hardware engineering requirements, onsite and offshore management of product development. Expert work on design and development for windows,web,mobile Expert knowledge of C#,ADO.NET, ASP.Net MVC, ENTITY FRAMEWORK, LINQ,COLLECTIONS, JAVASCRIPT,AngularJs 1.0,Angular2, Jquery,Jquery-Ajax, SQL SERVER, XAML,Windows phone 8.1 Good knowledge of WCF-Restful services,WCF, WEB API-Services ,Web- Services,MIcrosoft-Azure,JUICE UI,HTML,CSS,AJAX Read More...

Join him on Google+ | Facebook | Linkedin

No comments