IF ELSE statement usage in SQL

Source: Internet
Author: User
Tags sql using

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.