You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following SELECT statement, there is a group of four nested calls to the REPLACE function. This group is equivalent to the one call made to the TRANSLATE function in the preceding SELECT:
76
76
77
-
```syntaxsql
77
+
```sql
78
78
SELECT
79
79
REPLACE
80
80
(
@@ -103,7 +103,7 @@ REPLACE
103
103
104
104
GeoJSON is a format for encoding a variety of geographic data structures. With the `TRANSLATE` function, developers can easily convert GeoJSON points to WKT format and vice versa. The following query replaces square and curly braces in input with regular braces:
Copy file name to clipboardExpand all lines: docs/t-sql/language-elements/else-if-else-transact-sql.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,14 +52,14 @@ IF Boolean_expression
52
52
### A. Using a simple Boolean expression
53
53
The following example has a simple Boolean expression (`1=1`) that is true and, therefore, prints the first statement.
54
54
55
-
```syntaxsql
55
+
```sql
56
56
IF 1=1 PRINT 'Boolean_expression is true.'
57
57
ELSE PRINT 'Boolean_expression is false.' ;
58
58
```
59
59
60
60
The following example has a simple Boolean expression (`1=2`) that is false, and therefore prints the second statement.
61
61
62
-
```syntaxsql
62
+
```sql
63
63
IF 1=2 PRINT 'Boolean_expression is true.'
64
64
ELSE PRINT 'Boolean_expression is false.' ;
65
65
GO
@@ -68,7 +68,7 @@ GO
68
68
### B. Using a query as part of a Boolean expression
69
69
The following example executes a query as part of the Boolean expression. Because there are 10 bikes in the `Product` table that meet the `WHERE` clause, the first print statement will execute. Change `> 5` to `> 15` to see how the second part of the statement could execute.
70
70
71
-
```
71
+
```sql
72
72
USE AdventureWorks2012;
73
73
GO
74
74
IF
@@ -81,7 +81,7 @@ GO
81
81
### C. Using a statement block
82
82
The following example executes a query as part of the Boolean expression and then executes slightly different statement blocks based on the result of the Boolean expression. Each statement block starts with `BEGIN` and completes with `END`.
83
83
84
-
```
84
+
```sql
85
85
USE AdventureWorks2012;
86
86
GO
87
87
DECLARE @AvgWeight decimal(8,2), @BikeCount int
@@ -113,7 +113,7 @@ GO
113
113
### D. Using nested IF...ELSE statements
114
114
The following example shows how an IF ... ELSE statement can be nested inside another. Set the `@Number` variable to `5`, `50`, and `500` to test each statement.
115
115
116
-
```
116
+
```sql
117
117
DECLARE @Numberint;
118
118
SET @Number=50;
119
119
IF @Number>100
@@ -133,7 +133,7 @@ GO
133
133
### E: Using a query as part of a Boolean expression
134
134
The following example uses `IF...ELSE` to determine which of two responses to show the user, based on the weight of an item in the `DimProduct` table.
A partitioned view on `Server1` is defined in the following way:
206
206
207
-
```
207
+
```sql
208
208
--Partitioned view as defined on Server1
209
209
CREATEVIEWCustomers
210
210
AS
@@ -223,7 +223,7 @@ FROM Server3.CompanyData.dbo.Customers_99;
223
223
224
224
Generally, a view is said to be a partitioned view if it is of the following form:
225
225
226
-
```
226
+
```syntaxsql
227
227
SELECT <select_list1>
228
228
FROM T1
229
229
UNION ALL
@@ -247,21 +247,21 @@ FROM Tn;
247
247
248
248
Constraint `C1` defined on table `T1` must be of the following form:
249
249
250
-
syntaxsql
250
+
```syntaxsql
251
251
C1 ::= < simple_interval > [ OR < simple_interval > OR ...]
252
252
< simple_interval > :: =
253
253
< col > { < | > | \<= | >= | = < value >}
254
254
| < col > BETWEEN < value1 > AND < value2 >
255
255
| < col > IN ( value_list )
256
256
| < col > { > | >= } < value1 > AND
257
257
< col > { < | <= } < value2 >
258
-
syntaxsql
258
+
```
259
259
260
260
- The constraints must be in such a way that any specified value of `<col>` can satisfy, at most, one of the constraints `C1, ..., Cn` so that the constraints form a set of disjointed or nonoverlapping intervals. The column `<col>` on which the disjointed constraints are defined is called the partitioning column. Note that the partitioning column may have different names in the underlying tables. The constraints must be in an enabled and trusted state for them to meet the previously mentioned conditions of the partitioning column. If the constraints are disabled, re-enable constraint checking by using the CHECK CONSTRAINT *constraint_name* option of ALTER TABLE, and using the WITH CHECK option to validate them.
261
261
262
262
The following examples show valid sets of constraints:
263
263
264
-
syntaxsql
264
+
```syntaxsql
265
265
{ [col < 10], [col between 11 and 20] , [col > 20] }
266
266
{ [col between 11 and 20], [col between 21 and 30], [col between 31 and 100] }
267
267
```
@@ -350,7 +350,7 @@ The following examples use the AdventureWorks 2012 or AdventureWorksDW database.
350
350
### A. Using a simple CREATE VIEW
351
351
The following example creates a view by using a simple `SELECT` statement. A simple view is helpful when a combination of columns is queried frequently. The data from this view comes from the `HumanResources.Employee` and `Person.Person` tables of the [!INCLUDE[ssSampleDBnormal](../../includes/sssampledbnormal-md.md)] database. The data provides name and hire date information for the employees of [!INCLUDE[ssSampleDBCoFull](../../includes/sssampledbcofull-md.md)]. The view could be created for the person in charge of tracking work anniversaries but without giving this person access to all the data in these tables.
**Applies to**: [!INCLUDE[ssKatmai](../../includes/sskatmai-md.md)] and later and [!INCLUDE[ssSDS](../../includes/sssds-md.md)].
367
367
368
-
```
368
+
```sql
369
369
CREATEVIEWPurchasing.PurchaseOrderReject
370
370
WITH ENCRYPTION
371
371
AS
@@ -381,7 +381,7 @@ GO
381
381
### C. Using WITH CHECK OPTION
382
382
The following example shows a view named `SeattleOnly` that references five tables and allows for data modifications to apply only to employees who live in Seattle.
The following example shows a view definition that includes a built-in function. When you use functions, you must specify a column name for the derived column.
404
404
405
-
```
405
+
```sql
406
406
CREATEVIEWSales.SalesPersonPerform
407
407
AS
408
408
SELECT TOP (100) SalesPersonID, SUM(TotalDue) AS TotalSales
@@ -416,7 +416,7 @@ GO
416
416
### E. Using partitioned data
417
417
The following example uses tables named `SUPPLY1`, `SUPPLY2`, `SUPPLY3`, and `SUPPLY4`. These tables correspond to the supplier tables from four offices, located in different countries/regions.
418
418
419
-
```
419
+
```sql
420
420
--Create the tables and insert the values.
421
421
CREATETABLEdbo.SUPPLY1 (
422
422
supplyID INTPRIMARY KEYCHECK (supplyID BETWEEN 1and150),
@@ -463,7 +463,7 @@ GO
463
463
### F. Creating a simple view
464
464
The following example creates a view by selecting only some of the columns from the source table.
465
465
466
-
```
466
+
```sql
467
467
CREATEVIEWDimEmployeeBirthDatesAS
468
468
SELECT FirstName, LastName, BirthDate
469
469
FROM DimEmployee;
@@ -472,7 +472,7 @@ FROM DimEmployee;
472
472
### G. Create a view by joining two tables
473
473
The following example creates a view by using a `SELECT` statement with an `OUTER JOIN`. The results of the join query populate the view.
@@ -64,7 +64,7 @@ The following output shows the result:
64
64
### B. Using the query() method against an XML type column
65
65
In the following example, the **query()** method is used to specify an XQuery against the **CatalogDescription** column of **xml** type in the **AdventureWorks** database:
@@ -94,7 +94,7 @@ The following output shows the partial result:
94
94
95
95
Note the query() and exist() methods both declare the PD prefix. In these cases, you can use WITH XMLNAMESPACES to first define the prefixes and use it in the query.
0 commit comments