-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathif-stmt.html
More file actions
60 lines (58 loc) · 3.25 KB
/
if-stmt.html
File metadata and controls
60 lines (58 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>IF Statement - SQL Notebook</title>
<link rel="stylesheet" href="sqlnotebook.css">
</head>
<body>
<header>
<table class="nav">
<tr>
<td>
<a href="index.html"><img src="art/SqlNotebookIcon.png" alt="SQL Notebook (logo)" style="width: 58px; height: 58px; float: left; margin-right: 20px;"></a>
</td>
<td>
<a href="index.html" id="title">SQL Notebook</a><br>
<nav>
<ul class="nav">
<li><a href="https://github.com/brianluft/sqlnotebook/releases">Download</a></li>
<li><a href="doc.html"><span id="header-doc-long">Documentation</span><span id="header-doc-short">Docs</span></a></li>
<li><a href="https://github.com/brianluft/sqlnotebook">GitHub</a></li>
</ul>
</nav>
</td>
</tr>
</table>
<hr style="margin-top: 15px; margin-bottom: 15px;">
</header>
<article><div id="article">
<h1><code>IF</code> Statement</h1>Takes one code path or the other based on an SQL expression. The <span style=
"font-style: italic;">condition</span> expression must evaluate to the integer 0 or 1.
<h2>Syntax</h2><img src="art/if-stmt-syntax.svg" alt="" class="railroad" moz-do-not-send="true" width="604" height=
"311"><br>
<h2>Parameters</h2>
<ul class="args">
<li><i>condition</i>: integer (0-1)<br>
If this expression evaluates to 1, then the <span style="font-style: italic;">statement-if-true</span> statements
are executed. Otherwise, the <span style="font-style: italic;">statement-if-false</span> statements are
executed.</li>
<li><i>statement-if-true</i>: statement<br>
The statements to execute if the condition is 1. If more than one <span style=
"font-style: italic;">statement-if-true</span> statement is desired, the <code>BEGIN</code> and <code>END</code>
keywords must be used.</li>
<li><i>statement-if-false</i>: statement<br>
The statements to execute if the condition is 0. If more than one <span style=
"font-style: italic;">statement-if-false</span> statement is desired, the <code>BEGIN</code> and <code>END</code>
keywords must be used.</li>
</ul>
<h2>Example</h2>
<pre>DECLARE PARAMETER @foo = 111;<br>DECLARE PARAMETER @bar = 222;<br><br><i>-- The simplest IF tests a condition and executes a single</i><i><br></i><i>-- statement if true.</i><br>IF 1 <i>-- Always true.</i><br> PRINT 'Hi'; <i>-- Always prints.</i><br><br>IF @foo = 123<br> PRINT 'Hi'; <i>-- Prints or not depending on @foo.</i><br><br><i>-- An ELSE block will run if the IF condition is false.</i><i><br></i>IF @foo > @bar<br> PRINT 'Foo';<br>ELSE<br> PRINT 'Bar';<br><br><i>-- Check a series of conditions with ELSE IF.</i><br>IF @foo = 111<br> PRINT 'First condition'<br>ELSE IF @bar = 111<br> PRINT 'Second condition'<br>ELSE IF @foo = 222 AND @bar = 222<br> PRINT 'Third condition'<br>ELSE<br> PRINT 'None of the above'<br><br><i>-- Add BEGIN and END to any block to execute multiple statements.</i><br>IF @foo = 111 BEGIN<br> PRINT 'Hello...'<br> PRINT 'World!'<br>END<br></pre>
</div></article>
<footer><div id="footer">
<hr>
© 2016-2025 <a href="https://github.com/electroly">Brian Luft</a>
</div></footer>
</body>
</html>