About 727,000 results
Open links in new tab
  1. IF...ELSE (Transact-SQL) - SQL Server | Microsoft Learn

    Nov 22, 2024 · Syntax IF boolean_expression { sql_statement | statement_block } [ ELSE { sql_statement | statement_block } ] Arguments boolean_expression. An expression that returns TRUE or FALSE. If the Boolean expression contains a SELECT statement, the SELECT statement must be enclosed in parentheses. { sql_statement | …

  2. SQL Server IF ELSE Statement By Examples

    This tutorial shows you how to use the SQL Server IF...ELSE statement to control the flow of a program.

  3. sql server - How do I perform an IF...THEN in an SQL SELECT?

    Sep 15, 2008 · Simple if-else statement in SQL Server: DECLARE @val INT; SET @val = 15; IF @val < 25 PRINT 'Hi Ravi Anand'; ELSE PRINT 'By Ravi Anand.'; GO Nested If...else statement in SQL Server - DECLARE @val INT; SET @val = 15; IF @val < 25 PRINT 'Hi Ravi Anand.'; ELSE BEGIN IF @val < 50 PRINT 'what''s up?'; ELSE PRINT 'Bye Ravi Anand.'; END; GO

  4. Syntax of for-loop in SQL Server - Stack Overflow

    May 20, 2011 · There is no for-loop, only the while-loop: SET @i = @i + 1. /* do some work */ Be it noted that if you intend to use the index in the loop you may want to increment last thing instead of first, depending on your use case. Also note that …

  5. How to Use If Else in SQL Select Statement - GeeksforGeeks

    Jan 2, 2025 · In this article, We will explain how to use IF...ELSE in SQL with detailed syntax explanations, practical examples, and output. What is IF...ELSE in SQL? The IF...ELSE statement in SQL allows conditional execution of queries or operations based on specific conditions.

  6. SQL IF Statement for Conditional Logic - MSSQLTips.com - SQL Server

    Sep 12, 2022 · Here is the syntax that can be run in SQL Server Management Studio (SSMS): A variable is declared with a numeric type and set to the value of 1. The first IF statement uses an argument to compare that value to the constant zero. There are no …

  7. SQL Server: IF...ELSE Statement - TechOnTheNet

    This SQL Server tutorial explains how to use the IF...ELSE statement in SQL Server (Transact-SQL) with syntax and examples. In SQL Server, the IF...ELSE statement is used to execute code when a condition is TRUE, or execute different code if the condition evaluates to FALSE.

  8. sql server - While loop with if statements in SQL not working

    Aug 14, 2013 · I am trying to have if statements within a loop and it will continue to process until it gets what it wanted. Thanks for any response! DELETE FROM @tempTable. IF @SubjectCategoryID = 150 -- Village. BEGIN. INSERT INTO @tempTable. SELECT CommunityID, IsLocation from t_Loc_Village WHERE VillageID = @EntityID.

  9. Loops in SQL Server - Tutorial Ride

    SQL Server Loops - Tutorial to learn Loops in SQL Server in simple, easy and step by step way with syntax, examples and notes. Covers topics like IF..ELSE statement, WHILE LOOP, BREAK & CONTINUE Statement, GOTO Statement etc.

  10. IF ELSE StatementSQL Tutorial

    Here’s the basic syntax for using IF…ELSE in SQL Server: -- SQL statements to execute if the condition is TRUE. -- SQL statements to execute if the condition is FALSE. Condition: A Boolean expression that evaluates to TRUE or FALSE. BEGIN…END: Encapsulates a block of T …

  11. Some results have been removed
Refresh