Skip to content

Commit 1bda406

Browse files
authored
Merge pull request #36533 from rwestMSFT/rw-0129-fix-10275
Refresh operator precedence and bitwise shift articles (PR 10275)
2 parents a98b52c + ef29e17 commit 1bda406

4 files changed

Lines changed: 152 additions & 126 deletions

File tree

docs/t-sql/functions/left-shift-transact-sql.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "Transact-SQL reference for the LEFT_SHIFT function."
44
author: thesqlsith
55
ms.author: derekw
66
ms.reviewer: randolphwest
7-
ms.date: 07/26/2022
7+
ms.date: 01/29/2026
88
ms.service: sql
99
ms.subservice: t-sql
1010
ms.topic: reference
@@ -16,24 +16,26 @@ f1_keywords:
1616
helpviewer_keywords:
1717
- "bit manipulation [SQL Server], left shift"
1818
- "LEFT_SHIFT function"
19+
- "bitwise left shift"
1920
- "bit shifting [SQL Server], left shift"
2021
dev_langs:
2122
- "TSQL"
2223
monikerRange: ">=sql-server-ver16 || >=sql-server-linux-ver16 || =azuresqldb-mi-current || =azuresqldb-current || =fabric || =fabric-sqldb"
2324
---
2425
# LEFT_SHIFT (Transact SQL)
26+
2527
[!INCLUDE [SQL Server 2022, SQL Database, SQL Managed Instance FabricSE FabricDW FabricSQLDB](../../includes/applies-to-version/sqlserver2022-asdb-asmi-fabricse-fabricdw-fabricsqldb.md)]
2628

27-
LEFT_SHIFT takes two parameters, and returns the first parameter bit-shifted left by the number of bits specified in the second parameter.
29+
`LEFT_SHIFT` takes two parameters, and returns the first parameter bit-shifted left by the number of bits specified in the second parameter.
2830

29-
The LEFT_SHIFT function is also accessible through the `<<` operator.
31+
The `LEFT_SHIFT` function is also accessible through the `<<` operator.
3032

31-
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
33+
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
3234

3335
## Syntax
3436

3537
```syntaxsql
36-
LEFT_SHIFT ( expression_value, shift_amount )
38+
LEFT_SHIFT ( expression_value , shift_amount )
3739
expression_value << shift_amount
3840
```
3941

@@ -51,42 +53,41 @@ The number of bits by which *expression_value* should be shifted. *shift_amount*
5153

5254
Returns the same type as *expression_value*.
5355

54-
The *shift_amount* parameter is cast to a **bigint**. The parameter can be positive or negative, and can also be greater than the number of bits in the datatype of *expression_value*. When *shift_amount* is negative, the shift operates in the opposite direction. For example, `LEFT_SHIFT (expr, -1)` is the same as `RIGHT_SHIFT (expr, 1)`. When *shift_amount* is greater than the number of bits in *expression_value*, the result returned will be `0`.
56+
The *shift_amount* parameter is cast to a **bigint**. The parameter can be positive or negative, and can also be greater than the number of bits in the data type of *expression_value*. When *shift_amount* is negative, the shift operates in the opposite direction. For example, `LEFT_SHIFT (expr, -1)` is the same as `RIGHT_SHIFT (expr, 1)`. When *shift_amount* is greater than the number of bits in *expression_value*, the result returned is `0`.
5557

56-
LEFT_SHIFT performs a logical shift. After bits are shifted, any vacant positions will be filled by `0`, regardless of whether the original value was positive or negative.
58+
`LEFT_SHIFT` performs a logical shift. After bits are shifted, any vacant positions are filled by `0`, regardless of whether the original value was positive or negative.
5759

5860
## Remarks
5961

60-
In the initial implementation, Distributed Query functionality for the bit manipulation functions within linked server or ad hoc queries (OPENQUERY) won't be supported.
62+
In the initial implementation, Distributed Query functionality for the bit manipulation functions within linked server or ad hoc queries (`OPENQUERY`) isn't supported.
6163

62-
The `<<` method for the `LEFT_SHIFT` function is not currently supported in [!INCLUDE [fabric](../../includes/fabric.md)].
64+
The `<<` method for the `LEFT_SHIFT` function isn't currently supported in [!INCLUDE [fabric](../../includes/fabric.md)].
6365

6466
## Examples
6567

66-
In the following example, the integer value 12345 is left-shifted by 5 bits.
68+
In the following example, the integer value 12,345 is left-shifted by 5 bits.
6769

6870
```sql
6971
SELECT LEFT_SHIFT(12345, 5);
7072
```
7173

72-
The result is 395040. If you convert 12345 to binary, you have `0011 0000 0011 1001`. Shifting this to the left by 5 becomes `0110 0000 0111 0010 0000`, which is `395040` in decimal.
74+
The result is 395,040. If you convert 12,345 to binary, you have `0011 0000 0011 1001`. Shifting this value to the left by 5 bits becomes `0110 0000 0111 0010 0000`, which is `395040` in decimal.
7375

7476
The following table demonstrates what happens during each shift.
7577

76-
|Integer value|Binary value|Description|
77-
|---:|---:|---|
78-
|12345|`0011 0000 0011 1001`|Starting value|
79-
|24690|`0110 0000 0111 0010`|Shift left by 1|
80-
|49380|`1100 0000 1110 0100`|Shift left by 2|
81-
|98760|`0001 1000 0001 1100 1000`|Shift left by 3,<br/>and open into a new byte|
82-
|197520|`0011 0000 0011 1001 0000`|Shift left by 4|
83-
|395040|`0110 0000 0111 0010 0000`|Shift left by 5|
78+
| Integer value | Binary value | Description |
79+
| ---: | ---: | --- |
80+
| `12345` | `0011 0000 0011 1001` | Starting value |
81+
| `24690` | `0110 0000 0111 0010` | Shift left by 1 |
82+
| `49380` | `1100 0000 1110 0100` | Shift left by 2 |
83+
| `98760` | `0001 1000 0001 1100 1000` | Shift left by 3, and open into a new byte |
84+
| `197520` | `0011 0000 0011 1001 0000` | Shift left by 4 |
85+
| `395040` | `0110 0000 0111 0010 0000` | Shift left by 5 |
8486

85-
## See also
87+
## Related content
8688

8789
- [RIGHT_SHIFT (Transact SQL)](right-shift-transact-sql.md)
8890
- [SET_BIT (Transact SQL)](set-bit-transact-sql.md)
8991
- [GET_BIT (Transact SQL)](get-bit-transact-sql.md)
9092
- [BIT_COUNT (Transact SQL)](bit-count-transact-sql.md)
9193
- [Bit manipulation functions](bit-manipulation-functions-overview.md)
92-

docs/t-sql/functions/right-shift-transact-sql.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "Transact-SQL reference for the RIGHT_SHIFT function."
44
author: thesqlsith
55
ms.author: derekw
66
ms.reviewer: randolphwest
7-
ms.date: 07/26/2022
7+
ms.date: 01/29/2026
88
ms.service: sql
99
ms.subservice: t-sql
1010
ms.topic: reference
@@ -16,24 +16,26 @@ f1_keywords:
1616
helpviewer_keywords:
1717
- "bit manipulation [SQL Server], right shift"
1818
- "RIGHT_SHIFT function"
19+
- "bitwise right shift"
1920
- "bit shifting [SQL Server], right shift"
2021
dev_langs:
2122
- "TSQL"
2223
monikerRange: ">=sql-server-ver16 || >=sql-server-linux-ver16 || =azuresqldb-mi-current || =azuresqldb-current || =fabric || =fabric-sqldb"
2324
---
2425
# RIGHT_SHIFT (Transact SQL)
26+
2527
[!INCLUDE [SQL Server 2022, SQL Database, SQL Managed Instance FabricSE FabricDW FabricSQLDB](../../includes/applies-to-version/sqlserver2022-asdb-asmi-fabricse-fabricdw-fabricsqldb.md)]
2628

27-
RIGHT_SHIFT takes two parameters, and returns the first parameter bit-shifted right by the number of bits specified in the second parameter.
29+
`RIGHT_SHIFT` takes two parameters, and returns the first parameter bit-shifted right by the number of bits specified in the second parameter.
2830

29-
The RIGHT_SHIFT function is also accessible through the `>>` operator.
31+
The `RIGHT_SHIFT` function is also accessible through the `>>` operator.
3032

31-
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
33+
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
3234

3335
## Syntax
3436

3537
```syntaxsql
36-
RIGHT_SHIFT ( expression_value, shift_amount )
38+
RIGHT_SHIFT ( expression_value , shift_amount )
3739
expression_value >> shift_amount
3840
```
3941

@@ -51,42 +53,41 @@ The number of bits by which *expression_value* should be shifted. *shift_amount*
5153

5254
Returns the same type as *expression_value*.
5355

54-
The *shift_amount* parameter is cast to a **bigint**. The parameter can be positive or negative, and can also be greater than the number of bits in the datatype of *expression_value*. When *shift_amount* is negative, the shift operates in the opposite direction. For example, `LEFT_SHIFT (expr, -1)` is the same as `RIGHT_SHIFT (expr, 1)`. When *shift_amount* is greater than the number of bits in *expression_value*, the result returned will be `0`.
56+
The *shift_amount* parameter is cast to a **bigint**. The parameter can be positive or negative, and can also be greater than the number of bits in the data type of *expression_value*. When *shift_amount* is negative, the shift operates in the opposite direction. For example, `LEFT_SHIFT (expr, -1)` is the same as `RIGHT_SHIFT (expr, 1)`. When *shift_amount* is greater than the number of bits in *expression_value*, the result returned is `0`.
5557

56-
RIGHT_SHIFT performs a logical shift. After bits are shifted, any vacant positions will be filled by `0`, regardless of whether the original value was positive or negative.
58+
`RIGHT_SHIFT` performs a logical shift. After bits are shifted, any vacant positions are filled by `0`, regardless of whether the original value was positive or negative.
5759

5860
## Remarks
5961

60-
In the initial implementation, Distributed Query functionality for the bit manipulation functions within linked server or ad hoc queries (OPENQUERY) won't be supported.
62+
In the initial implementation, Distributed Query functionality for the bit manipulation functions within linked server or ad hoc queries (`OPENQUERY`) aren't supported.
6163

62-
The `>>` method for the `RIGHT_SHIFT` function is not currently supported in [!INCLUDE [fabric](../../includes/fabric.md)].
64+
The `>>` method for the `RIGHT_SHIFT` function isn't currently supported in [!INCLUDE [fabric](../../includes/fabric.md)].
6365

6466
## Examples
6567

66-
In the following example, the integer value 12345 is right-shifted by 5 bits.
68+
In the following example, the integer value 12,345 is right-shifted by 5 bits.
6769

6870
```sql
6971
SELECT RIGHT_SHIFT(12345, 5);
7072
```
7173

72-
The result is 385. If you convert 12345 to binary, you have `0011 0000 0011 1001`. Shifting this to the right by 5 becomes `0001 1000 0001`, which is `385` in decimal.
74+
The result is 385. If you convert 12,345 to binary, you have `0011 0000 0011 1001`. Shifting this value to the right by 5 bits becomes `0001 1000 0001`, which is `385` in decimal.
7375

7476
The following table demonstrates what happens during each shift.
7577

76-
|Integer value|Binary value|Description|
77-
|---:|---:|---|
78-
|12345|`0011 0000 0011 1001`|Starting value|
79-
|6172|`0001 1000 0001 1100`|Shift right by 1|
80-
|3086|`0000 1100 0000 1110`|Shift right by 2|
81-
|1543|`0000 0110 0000 0111`|Shift right by 3|
82-
|771|`0000 0011 0000 0011`|Shift right by 4|
83-
|385|`0000 0001 1000 0001`|Shift right by 5|
78+
| Integer value | Binary value | Description |
79+
| ---: | ---: | --- |
80+
| `12345` | `0011 0000 0011 1001` | Starting value |
81+
| `6172` | `0001 1000 0001 1100` | Shift right by 1 |
82+
| `3086` | `0000 1100 0000 1110` | Shift right by 2 |
83+
| `1543` | `0000 0110 0000 0111` | Shift right by 3 |
84+
| `771` | `0000 0011 0000 0011` | Shift right by 4 |
85+
| `385` | `0000 0001 1000 0001` | Shift right by 5 |
8486

85-
## See also
87+
## Related content
8688

8789
- [LEFT_SHIFT (Transact SQL)](left-shift-transact-sql.md)
8890
- [SET_BIT (Transact SQL)](set-bit-transact-sql.md)
8991
- [GET_BIT (Transact SQL)](get-bit-transact-sql.md)
9092
- [BIT_COUNT (Transact SQL)](bit-count-transact-sql.md)
9193
- [Bit manipulation functions](bit-manipulation-functions-overview.md)
92-
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
title: "Logical Operators (Transact-SQL)"
3-
description: "Logical Operators (Transact-SQL)"
3+
description: Logical operators test for the truth of some condition.
44
author: rwestMSFT
55
ms.author: randolphwest
6-
ms.date: "03/06/2017"
6+
ms.date: 01/29/2026
77
ms.service: sql
88
ms.subservice: t-sql
99
ms.topic: reference
@@ -17,25 +17,25 @@ helpviewer_keywords:
1717
dev_langs:
1818
- "TSQL"
1919
---
20-
# Logical Operators (Transact-SQL)
20+
# Logical operators (Transact-SQL)
21+
2122
[!INCLUDE [SQL Server Azure SQL Managed Instance](../../includes/applies-to-version/sql-asdbmi.md)]
2223

23-
Logical operators test for the truth of some condition. Logical operators, like comparison operators, return a **Boolean** data type with a value of TRUE, FALSE, or UNKNOWN.
24-
25-
|Operator|Meaning|
26-
|--------------|-------------|
27-
|[ALL](../../t-sql/language-elements/all-transact-sql.md)|TRUE if all of a set of comparisons are TRUE.|
28-
|[AND](../../t-sql/language-elements/and-transact-sql.md)|TRUE if both Boolean expressions are TRUE.|
29-
|[ANY](../../t-sql/language-elements/any-transact-sql.md)|TRUE if any one of a set of comparisons are TRUE.|
30-
|[BETWEEN](../../t-sql/language-elements/between-transact-sql.md)|TRUE if the operand is within a range.|
31-
|[EXISTS](../../t-sql/language-elements/exists-transact-sql.md)|TRUE if a subquery contains any rows.|
32-
|[IN](../../t-sql/language-elements/in-transact-sql.md)|TRUE if the operand is equal to one of a list of expressions.|
33-
|[LIKE](../../t-sql/language-elements/like-transact-sql.md)|TRUE if the operand matches a pattern.|
34-
|[NOT](../../t-sql/language-elements/not-transact-sql.md)|Reverses the value of any other Boolean operator.|
35-
|[OR](../../t-sql/language-elements/or-transact-sql.md)|TRUE if either Boolean expression is TRUE.|
36-
|[SOME](../../t-sql/language-elements/some-any-transact-sql.md)|TRUE if some of a set of comparisons are TRUE.|
37-
38-
## See Also
39-
[Operator Precedence &#40;Transact-SQL&#41;](../../t-sql/language-elements/operator-precedence-transact-sql.md)
40-
41-
24+
Logical operators test for the truth of some condition. Logical operators, like comparison operators, return a **Boolean** data type with a value of `TRUE`, `FALSE`, or `UNKNOWN`.
25+
26+
| Operator | Meaning |
27+
| --- | --- |
28+
| [ALL](all-transact-sql.md) | `TRUE` if all of a set of comparisons are `TRUE`. |
29+
| [AND](and-transact-sql.md) | `TRUE` if both Boolean expressions are `TRUE`. |
30+
| [ANY](any-transact-sql.md) | `TRUE` if any one of a set of comparisons are `TRUE`. |
31+
| [BETWEEN](between-transact-sql.md) | `TRUE` if the operand is within a range. |
32+
| [EXISTS](exists-transact-sql.md) | `TRUE` if a subquery contains any rows. |
33+
| [IN](in-transact-sql.md) | `TRUE` if the operand is equal to one of a list of expressions. |
34+
| [LIKE](like-transact-sql.md) | `TRUE` if the operand matches a pattern. |
35+
| [NOT](not-transact-sql.md) | Reverses the value of any other Boolean operator. |
36+
| [OR](or-transact-sql.md) | `TRUE` if either Boolean expression is `TRUE`. |
37+
| [SOME &#124; ANY](some-any-transact-sql.md) | `TRUE` if some of a set of comparisons are `TRUE`. |
38+
39+
## Related content
40+
41+
- [Operator precedence (Transact-SQL)](operator-precedence-transact-sql.md)

0 commit comments

Comments
 (0)