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
Copy file name to clipboardExpand all lines: articles/azure-sql-edge/date-bucket-tsql.md
+14-12Lines changed: 14 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,13 +13,13 @@ ms.date: 05/19/2019
13
13
14
14
# Date_Bucket (Transact-SQL)
15
15
16
-
This function distributes aggregate column expressions in different date or time boundaries.
16
+
This function returns the datetime value corresponding to the start of each datetime bucket, from the default origin value of `1900-01-01 00:00:00.000`.
17
17
18
18
See [Date and Time Data Types and Functions (Transact-SQL)](/sql/t-sql/functions/date-and-time-data-types-and-functions-transact-sql/) for an overview of all Transact-SQL date and time data types and functions.
`DATE_BUCKET` uses a default origin date value of `1900-01-01 00:00:00.000`for example, 12 AM on Monday the 1 January 1900.
22
+
`DATE_BUCKET` uses a default origin date value of `1900-01-01 00:00:00.000`i.e. 12:00 AM on Monday, January 1 1900.
23
23
24
24
## Syntax
25
25
@@ -38,20 +38,16 @@ The part of *date* that is used with the ‘number’ parameter. Ex. Year, month
38
38
39
39
|*datePart*|Abbreviations|
40
40
|---|---|
41
-
|**dayofyear**|**dy**, **y**|
42
41
|**day**|**dd**, **d**|
43
42
|**week**|**wk**, **ww**|
44
-
|**weekday**|**dw**, **w**|
45
43
|**hour**|**hh**|
46
44
|**minute**|**mi**, **n**|
47
45
|**second**|**ss**, **s**|
48
46
|**millisecond**|**ms**|
49
-
|**microsecond**|**mcs**|
50
-
|**nanosecond**|**ns**|
51
47
52
48
*number*
53
49
54
-
The integer number that decides the width of the bucket combined with *datePart* argument. This represents the width of the dataPart buckets from the origin time.
50
+
The integer number that decides the width of the bucket combined with *datePart* argument. This represents the width of the dataPart buckets from the origin time.**`This argument cannot be a negative integer value`**.
The *number* argument cannot exceed the range of **int**. In the following statements, the argument for *number* exceeds the range of **int** by 1. The following statement returns the following error message: "`Msg 8115, Level 16, State 2, Line 2. Arithmetic overflow error converting expression to data type int."`
103
+
The *number* argument cannot exceed the range of positive **int** values. In the following statements, the argument for *number* exceeds the range of **int** by 1. The following statement returns the following error message: "`Msg 8115, Level 16, State 2, Line 2. Arithmetic overflow error converting expression to data type int."`
108
104
109
105
```sql
110
106
declare @date datetime2 ='2020-04-30 00:00:00'
111
107
Select DATE_BUCKET(dd, 2147483648, @date)
112
108
```
113
-
109
+
110
+
If a negative value for number is passed to the `Date_Bucket` function, the following error will be returned.
111
+
112
+
```sql
113
+
Msg 9834, Level 16, State 1, Line1
114
+
Invalid bucket width value passed to date_bucket function. Only positive values are allowed.
115
+
````
116
+
114
117
## date Argument
115
118
116
-
`DATE_BUCKET` return the base value corresponding to the data type of the `date` argument. If the expression evaluation returns in a datetime overflow, `DATE_BUCKET` will return the default origin time of `1900-01-01 00:00:00.0000000`. For example, the first statement will return an error "`Msg 517, Level 16, State 3, Line 1 Adding a value to a 'datetime2' column caused an overflow."`, while the second statement will return the value `1900-01-01 00:00:00.0000000`
119
+
`DATE_BUCKET` return the base value corresponding to the data type of the `date` argument. In the following example, an output value with datetime2 datatype is returned.
0 commit comments