SQL Server Process Control

Source: Internet
Author: User

Process Control Statements:

BEGIN ... END WAITFOR Goto
While IF ... ELSE Break
RETURN Continure

1.BEGIN ... END

BEGIN ... The end statement is used to combine multiple Transact-SQL statements into a single logical block. When a Process Control statement must execute a block of statements that contains two or more T-SQL statements, use begin ... End statement.

1   BEGIN 2   {sql_statement ...} 3   END

2.IF

1 IF < conditional expression >2  | program Block}

IF ... ELSE

1   IF < conditional expressions >2     | program Block 1} 3   ELSE 4     | Program Block 2}

Code:

1 Declare @x int2   Set @x=43   if @x%2=04   Print '@x is even'5   Else6   Print '@x is an odd number'

3.CASE

1  Case input_expression 2      when  Then result_expression 3     [...n] 4     5     ELSE else_result_expression 6 7     END

Code:

1    UsePractice2   Go3   Select *Note= Case4    whenSex='Girl'  Then 'female'5    whenSex=' Boy'   Then 'male'6   Else 'not recognized'7   End8    fromInfo_stu

Effect:

4.WHILE

Code:

1 DECLARE @n int,@sum int2   Set @n=13 Set @sum=04  while @n<=Ten5   begin6   Set @sum=@sum+@n7   Set @n=@n+18   End9   Print @sum

Effect:

SQL Server Process Control

Related Article

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.