Monday, 6 August 2018

SQL Server IF ELSE

If condition is used for decision making purpose. If condition check Boolean value, if the condition is true then statement under if condition is executed or else controls goes to else part execute this statement. 


You can have more multiple if condition with else statement in a single query. If statement can be written under store procedures , function, Trigger, query for decision making purpose. 


Below is the picture real view of if condition.






1)Below is the syntax of if condition.



IF condition
   {...statements to execute when condition is TRUE...}

[ ELSE
   {...statements to execute when condition is FALSE...} ]
 
 
2)Below is the example of if condition.

Declare @myValue INT=10

IF (@myValue < 25)
          PRINT 'Value_1';
ELSE
          PRINT 'Value_2';




3)Here is the example of if condition with multiple if.


 
Declare @myValue INT=10

IF (@myValue =10)
          PRINT 'Value 10';
ELSE IF (@myValue =15)
          PRINT 'Value 15';
ELSE IF (@myValue =20)
         PRINT 'Value 20';
ELSE IF (@myValue =22)
         PRINT 'Value 22';
ELSE
         PRINT 'Value_2';



No comments:

Post a Comment

বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...