IF ELSE Statement
IF ELSE is one of the most basic programming statement structures in which almost every programming language supports this structure and
It is useful to check the data returned from the database for Transact-SQL using the IF ELSE
The examples are as follows
Grammar
if (condition)
Begin
(Statement block)
End
else if (condition)
Begin
Statement block)
End
Else
Begin
(Statement block)
End
Note that when the specified condition is true, the BEGIN END statement block is executed at the same time
You should also be aware that it is a good programming habit to indent each statement into a certain amount of space, which can be greatly raised
The readability of your program and errors caused by poor legibility
Instance:
Declare @id int Set @id = +if(@id> -)begin Print('Greater than');End Else Print('less than or equal to')/* There is only one line of statements and you do not need to add begin end*/
IF ELSE statement usage in SQL