Collections:
IF ... ELSE Statement in SQL Server Transact-SQL
How to execute statements under given conditions in SQL Server Transact-SQL? How to use IF ... ELSE statements?
✍: FYIcenter.com
You can use IF ... ELSE statements to execute statements under given
conditions in Transact-SQL using these syntaxes:
IF condition statement_1
IF condition statement_1
ELSE statement_2
IF condition
-- statement_block_1
BEGIN
... statements ...
END
IF condition
-- statement_block_1
BEGIN
... statements ...
END
ELSE
-- statement_block_2
BEGIN
... statements ...
END
When a IF...ELSE statement is executed, the system will:
Here is an example on how to use IF ... ELSE conditional statements:
IF DATENAME(weekday, GETDATE()) IN ('Saturday', 'Sunday')
BEGIN
PRINT 'It''s a weekend.';
PRINT 'You can stay home.';
END
ELSE
BEGIN
PRINT 'It''s a weekday.';
PRINT 'You need to go to work.';
END
⇒ "IF ... ELSE IF ..." Statement Structures in SQL Server
⇐ BEGIN ... END Statement Blocks in SQL Server Transact-SQL
⇑ Conditional Statements and Loops in SQL Server in SQL Server Transact-SQL
2017-01-11, 4318🔥, 0💬
Popular Posts:
What Happens If the Imported Table Already Exists in Oracle? If the import process tries to import a...
How To Use DATEADD() Function in SQL Server Transact-SQL? DATEADD() is a very useful function for ma...
How To Divide Query Output into Multiple Groups with the GROUP BY Clause in SQL Server? Sometimes, y...
How To Format Time Zone in +/-hh:mm Format in SQL Server Transact-SQL? From the previous tutorial, y...
How To List All Stored Procedures in the Current Database in SQL Server Transact-SQL? If you want to...