SQL SERVER | Conditional Statements Last Updated : 27 Jan, 2022 Comments Improve Suggest changes Like Article Like Report While loop: In SQL SERVER, while loop can be used in similar manner as any other programming language. A while loop will check the condition first and then execute the block of SQL Statements within it as long as the condition evaluates true. Syntax: WHILE condition BEGIN {...statements...} END; Parameters: 1. Condition: The condition is tested in each pass through the loop. If condition evaluates to TRUE, the loop body is executed otherwise the loop is terminated. 2. Statements: The statements that needs to be executed in each pass through the loop. Example: Output: Break statement: BREAK statement as the name signifies is used to break the flow of control. It can be used in SQL in similar manner as any other programming language. Example: While loop with Break statement Output: Note : In the example, when variables value became five, BREAK Statement is executed and the control gets out from the Loop. Do-While loop: SQL server does not have the feature of do-while loop but by doing little modifications in while loop, the same behaviour can be achieved. Example 1: Output: Example 2: Output: CASE statement: In SQL Server, the CASE statement has the same functionality as IF-THEN-ELSE statement. Syntax: CASE Expression WHEN Con_1 THEN Output1 WHEN Con_2 THEN Output2 WHEN Con_3 THEN Output3 WHEN Con_4 THEN Output4 ... WHEN Con_n THEN Outputn ELSE output END Parameters: 1. Expression: The value to be compared to the list of conditions(Optional). 2. Con_1, Con_2, ...Con_n: The conditions are required and are evaluated in the order they are listed. Once a condition is true, the CASE function will return the result and not evaluate the conditions any further. 3. Output1, Output2, ...Outputn: The output to be printed once the condition evaluates true. Example: Output: Comment More infoAdvertise with us Next Article SQL SERVER | Conditional Statements S Sam007 Follow Improve Article Tags : SQL SQL-Server Similar Reads Select Statement in MS SQL Server The SELECT statement in SQL Server is a foundational SQL command used for querying and retrieving data from one or more tables within a database. This command allows users to specify which columns and rows to retrieve and apply filters to focus on specific data and perform various operations to mani 4 min read SQL CASE Statement The CASE statement in SQL is a versatile conditional expression that enables us to incorporate conditional logic directly within our queries. It allows you to return specific results based on certain conditions, enabling dynamic query outputs. Whether you need to create new columns, modify existing 4 min read SQL SERVER | IN Condition IN condition is an alternative to multiple OR conditions in SELECT, INSERT, UPDATE, or DELETE statement. The IN operator allows multiple values to be tested against the expression and thus reduces the use of multiple OR conditions with each test value. Syntax: expression IN (value1, value2, .... val 1 min read SQL SELECT IN Statement The IN operator in SQL is used to compare a column's value against a set of values. It returns TRUE if the column's value matches any of the values in the specified list, and FALSE if there is no match.In this article, we will learn how IN operator works and provide practical examples to help you be 3 min read Conditional Summation in SQL In data manipulation, SQL (Structured Query Language) stands as a powerful tool for extracting, transforming, and analyzing data stored in relational databases. Among its numerous functionalities, SQL provides robust capabilities for summation operations, allowing users to aggregate data according t 5 min read SQL | Conditional Expressions In SQL, conditional expressions are essential for making decisions based on certain conditions directly within queries. These expressions allow us to apply business logic, to return values based on conditions, and transform data without using complex procedures. The CASE, DECODE, COALESCE, GREATEST, 4 min read SQL CREATE VIEW Statement The SQL CREATE VIEW statement is a very powerful feature in RDBMSs that allows users to create virtual tables based on the result set of a SQL query. Unlike regular tables, these views do not store data themselves rather they provide a way of dynamically retrieving and presenting data from one or ma 4 min read Where clause in MS SQL Server In this article, where clause will be discussed alongside example. Introduction : To extract the data at times, we need a particular conditions to satisfy. 'where' is a clause used to write the condition in the query. Syntax : select select_list from table_name where condition A example is given bel 1 min read Conditional Join DBMS or Database Management Systems consist of data collected from various sources. Database administrators and analysts use this data to analyze the collected data. Database administrators execute the query through which some output is generated, the conditions are passed through the query. This qu 5 min read Like