Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 7109b77

Browse files
authored
Merge pull request #8959 from WilliamAntonRohm/t-sql-3
improving Acrolinx scores for T-SQL articles -- third batch
2 parents a105430 + d82d228 commit 7109b77

5 files changed

Lines changed: 41 additions & 48 deletions

File tree

docs/t-sql/data-types/precision-scale-and-length-transact-sql.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ Precision is the number of digits in a number. Scale is the number of digits to
3030

3131
In [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)], the default maximum precision of **numeric** and **decimal** data types is 38. In earlier versions of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)], the default maximum is 28.
3232

33-
Length for a numeric data type is the number of bytes that are used to store the number. Length for a character string or Unicode data type is the number of characters. The length for **binary**, **varbinary**, and **image** data types is the number of bytes. For example, an **int** data type can hold 10 digits, is stored in 4 bytes, and does not accept decimal points. The **int** data type has a precision of 10, a length of 4, and a scale of 0.
33+
Length for a numeric data type is the number of bytes that are used to store the number. Length for a character string or Unicode data type is the number of characters. The length for **binary**, **varbinary**, and **image** data types is the number of bytes. For example, an **int** data type can hold 10 digits, is stored in 4 bytes, and doesn't accept decimal points. The **int** data type has a precision of 10, a length of 4, and a scale of 0.
3434

35-
When two **char**, **varchar**, **binary**, or **varbinary** expressions are concatenated, the length of the resulting expression is the sum of the lengths of the two source expressions or 8,000 characters, whichever is less.
35+
When concatenating two **char**, **varchar**, **binary**, or **varbinary** expressions, the length of the resulting expression is the sum of the lengths of the two source expressions, up to 8,000 characters.
3636

37-
When two **nchar** or **nvarchar** expressions are concatenated, the length of the resulting expression is the sum of the lengths of the two source expressions or 4,000 characters, whichever is less.
37+
When concatenating two **nchar** or **nvarchar** expressions, the length of the resulting expression is the sum of the lengths of the two source expressions, up to 4,000 characters.
3838

39-
When two expressions of the same data type but different lengths are compared by using UNION, EXCEPT, or INTERSECT, the resulting length is the maximum length of the two expressions.
39+
When comparing two expressions of the same data type but different lengths by using UNION, EXCEPT, or INTERSECT, the resulting length is the longer of the two expressions.
4040

41-
The precision and scale of the numeric data types besides **decimal** are fixed. If an arithmetic operator has two expressions of the same type, the result has the same data type with the precision and scale defined for that type. If an operator has two expressions with different numeric data types, the rules of data type precedence define the data type of the result. The result has the precision and scale defined for its data type.
41+
The precision and scale of the numeric data types besides **decimal** are fixed. When an arithmetic operator has two expressions of the same type, the result has the same data type with the precision and scale defined for that type. If an operator has two expressions with different numeric data types, the rules of data type precedence define the data type of the result. The result has the precision and scale defined for its data type.
4242

43-
The following table defines how the precision and scale of the result are calculated when the result of an operation is of type **decimal**. The result is **decimal** when either of the following is true:
43+
The following table defines how the precision and scale of the result are calculated when the result of an operation is of type **decimal**. The result is **decimal** when either:
4444
- Both expressions are **decimal**.
4545
- One expression is **decimal** and the other is a data type with a lower precedence than **decimal**.
4646

47-
The operand expressions are denoted as expression e1, with precision p1 and scale s1, and expression e2, with precision p2 and scale s2. The precision and scale for any expression that is not **decimal** is the precision and scale defined for the data type of the expression.
47+
The operand expressions are denoted as expression e1, with precision p1 and scale s1, and expression e2, with precision p2 and scale s2. The precision and scale for any expression that isn't **decimal** is that of the data type of the expression.
4848

4949
|Operation|Result precision|Result scale *|
5050
|---|---|---|
@@ -55,32 +55,31 @@ The operand expressions are denoted as expression e1, with precision p1 and scal
5555
|e1 { UNION | EXCEPT | INTERSECT } e2|max(s1, s2) + max(p1-s1, p2-s2)|max(s1, s2)|
5656
|e1 % e2|min(p1-s1, p2 -s2) + max( s1,s2 )|max(s1, s2)|
5757

58-
\* The result precision and scale have an absolute maximum of 38. When a result precision is greater than 38, it is reduced to 38, and the corresponding scale is reduced to try to prevent the integral part of a result from being truncated. In some cases such as multiplication or division, scale factor will not be reduced in order to keep decimal precision, although the overflow error can be raised.
58+
\* The result precision and scale have an absolute maximum of 38. When a result precision is greater than 38, it's reduced to 38, and the corresponding scale is reduced to try to prevent truncating the integral part of a result. In some cases such as multiplication or division, scale factor won't be reduced, to maintain decimal precision, although the overflow error can be raised.
5959

60-
In addition and subtraction operations we need `max(p1 - s1, p2 - s2)` places to store integral part of the decimal number. If there is not enough space to store them i.e. `max(p1 - s1, p2 - s2) < min(38, precision) - scale`, the scale is reduced to provide enough space for integral part. Resulting scale is `MIN(precision, 38) - max(p1 - s1, p2 - s2)`, so the fractional part might be rounded to fit into the resulting scale.
60+
In addition and subtraction operations, we need `max(p1 - s1, p2 - s2)` places to store integral part of the decimal number. If there isn't enough space to store them that is, `max(p1 - s1, p2 - s2) < min(38, precision) - scale`, the scale is reduced to provide enough space for integral part. Resulting scale is `MIN(precision, 38) - max(p1 - s1, p2 - s2)`, so the fractional part might be rounded to fit into the resulting scale.
6161

62-
In multiplication and division operations we need `precision - scale` places to store the integral part of the result. The scale might be reduced using the following rules:
63-
1. The resulting scale is reduced to `min(scale, 38 - (precision-scale))` if the integral part is less than 32, because it cannot be greater than `38 - (precision-scale)`. Result might be rounded in this case.
64-
1. The scale will not be changed if it is less than 6 and if the integral part is greater than 32. In this case, overflow error might be raised if it cannot fit into decimal(38, scale)
65-
1. The scale will be set to 6 if it is greater than 6 and if the integral part is greater than 32. In this case, both integral part and scale would be reduced and resulting type is decimal(38,6). Result might be rounded to 6 decimal places or overflow error will be thrown if integral part cannot fit into 32 digits.
62+
In multiplication and division operations, we need `precision - scale` places to store the integral part of the result. The scale might be reduced using the following rules:
63+
1. The resulting scale is reduced to `min(scale, 38 - (precision-scale))` if the integral part is less than 32, because it can't be greater than `38 - (precision-scale)`. Result might be rounded in this case.
64+
1. The scale won't be changed if it's less than 6 and if the integral part is greater than 32. In this case, overflow error might be raised if it can't fit into decimal(38, scale)
65+
1. The scale will be set to 6 if it's greater than 6 and if the integral part is greater than 32. In this case, both integral part and scale would be reduced and resulting type is decimal(38,6). Result might be rounded to 6 decimal places or the overflow error will be thrown if the integral part can't fit into 32 digits.
6666

6767
## Examples
6868
The following expression returns result `0.00000090000000000` without rounding, because result can fit into `decimal(38,17)`:
6969
```sql
7070
select cast(0.0000009000 as decimal(30,20)) * cast(1.0000000000 as decimal(30,20)) [decimal 38,17]
7171
```
7272
In this case precision is 61, and scale is 40.
73-
Integral part (precision-scale = 21) is less than 32, so this is case (1) in multiplication rules and scale is calculated as `min(scale, 38 - (precision-scale)) = min(40, 38 - (61-40)) = 17`. Result type is `decimal(38,17)`.
73+
Integral part (precision-scale = 21) is less than 32, so this case is case (1) in multiplication rules and scale is calculated as `min(scale, 38 - (precision-scale)) = min(40, 38 - (61-40)) = 17`. Result type is `decimal(38,17)`.
7474

7575
The following expression returns result `0.000001` to fit into `decimal(38,6)`:
7676
```sql
7777
select cast(0.0000009000 as decimal(30,10)) * cast(1.0000000000 as decimal(30,10)) [decimal(38, 6)]
7878
```
7979
In this case precision is 61, and scale is 20.
80-
Scale is greater than 6 and integral part (`precision-scale = 41`) is greater than 32. This is case (3) in multiplication rules and result type is `decimal(38,6)`.
80+
Scale is greater than 6 and integral part (`precision-scale = 41`) is greater than 32. This case is case (3) in multiplication rules and result type is `decimal(38,6)`.
8181

8282
## See also
8383
[Expressions &#40;Transact-SQL&#41;](../../t-sql/language-elements/expressions-transact-sql.md)
8484
[Data Types &#40;Transact-SQL&#41;](../../t-sql/data-types/data-types-transact-sql.md)
8585

86-

docs/t-sql/functions/percentile-cont-transact-sql.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ PERCENTILE_CONT ( numeric_literal )
4141
The percentile to compute. The value must range between 0.0 and 1.0.
4242

4343
WITHIN GROUP **(** ORDER BY *order_by_expression* [ **ASC** | DESC ]**)**
44-
Specifies a list of numeric values to sort and compute the percentile over. Only one *order_by_expression* is allowed. The expression must evaluate to an exact numeric type (**int**, **bigint**, **smallint**, **tinyint**, **numeric**, **bit**, **decimal**, **smallmoney**, **money**) or an approximate numeric type (**float**, **real**). Other data types are not allowed. The default sort order is ascending.
44+
Specifies a list of numeric values to sort and compute the percentile over. Only one *order_by_expression* is allowed. The expression must evaluate to an exact or approximate numeric type, with no other data types allowed. Exact numeric types are **int**, **bigint**, **smallint**, **tinyint**, **numeric**, **bit**, **decimal**, **smallmoney**, and **money**. Approximate numeric types are **float** and **real**. The default sort order is ascending.
4545

4646
OVER **(** \<partition_by_clause> **)**
47-
Divides the result set produced by the FROM clause into partitions to which the percentile function is applied. For more information, see [OVER Clause &#40;Transact-SQL&#41;](../../t-sql/queries/select-over-clause-transact-sql.md). The \<ORDER BY clause> and \<rows or range clause> of the OVER syntax cannot be specified in a PERCENTILE_CONT function.
47+
Divides the result set produced by the FROM clause into partitions to which the percentile function is applied. For more information, see [OVER Clause &#40;Transact-SQL&#41;](../../t-sql/queries/select-over-clause-transact-sql.md). The \<ORDER BY clause> and \<rows or range clause> of the OVER syntax can't be specified in a PERCENTILE_CONT function.
4848

4949
## Return Types
5050
**float(53)**
@@ -60,7 +60,7 @@ PERCENTILE_CONT ( numeric_literal )
6060
## Examples
6161

6262
### A. Basic syntax example
63-
The following example uses PERCENTILE_CONT and PERCENTILE_DISC to find the median employee salary in each department. Note that these functions may not return the same value. This is because PERCENTILE_CONT interpolates the appropriate value, whether or not it exists in the data set, while PERCENTILE_DISC always returns an actual value from the set.
63+
The following example uses PERCENTILE_CONT and PERCENTILE_DISC to find the median employee salary in each department. These functions may not return the same value. PERCENTILE_CONT interpolates the appropriate value, which may or may not exist in the data set, while PERCENTILE_DISC always returns an actual value from the set.
6464

6565
```
6666
USE AdventureWorks2012;
@@ -92,7 +92,7 @@ Human Resources 17.427850 16.5865
9292
## Examples: [!INCLUDE[ssSDWfull](../../includes/sssdwfull-md.md)] and [!INCLUDE[ssPDW](../../includes/sspdw-md.md)]
9393

9494
### B. Basic syntax example
95-
The following example uses PERCENTILE_CONT and PERCENTILE_DISC to find the median employee salary in each department. Note that these functions may not return the same value. This is because PERCENTILE_CONT interpolates the appropriate value, whether or not it exists in the data set, while PERCENTILE_DISC always returns an actual value from the set.
95+
The following example uses PERCENTILE_CONT and PERCENTILE_DISC to find the median employee salary in each department. These functions may not return the same value. PERCENTILE_CONT interpolates the appropriate value, which may or may not exist in the data set, while PERCENTILE_DISC always returns an actual value from the set.
9696

9797
```
9898
-- Uses AdventureWorks
@@ -120,6 +120,4 @@ Shipping and Receiving 9.250000 9.0000
120120
## See Also
121121
[PERCENTILE_DISC &#40;Transact-SQL&#41;](../../t-sql/functions/percentile-disc-transact-sql.md)
122122

123-
124-
125-
123+

0 commit comments

Comments
 (0)