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
An [expression](../../t-sql/language-elements/expressions-transact-sql.md) of any type. Expressions are converted to **nvarchar** or **varchar** types during concatenation. Non-string types are converted to **nvarchar** type.
41
+
An [expression](../language-elements/expressions-transact-sql.md) of any type. Expressions are converted to **nvarchar** or **varchar** types during concatenation. Non-string types are converted to **nvarchar** type.
42
42
43
43
#### *separator*
44
44
45
-
An [expression](../../t-sql/language-elements/expressions-transact-sql.md) of **nvarchar** or **varchar** type that is used as separator for concatenated strings. It can be literal or variable.
45
+
An [expression](../language-elements/expressions-transact-sql.md) of **nvarchar** or **varchar** type that is used as separator for concatenated strings. It can be literal or variable.
46
46
47
47
#### <order_clause>
48
48
@@ -54,7 +54,7 @@ WITHIN GROUP ( ORDER BY <order_by_expression_list> [ ASC | DESC ] )
54
54
55
55
-`<order_by_expression_list>`
56
56
57
-
A list of non-constant [expressions](../../t-sql/language-elements/expressions-transact-sql.md) that can be used for sorting results. Only one `<order_by_expression_list>` is allowed per query. The default sort order is ascending.
57
+
A list of non-constant [expressions](../language-elements/expressions-transact-sql.md) that can be used for sorting results. Only one `<order_by_expression_list>` is allowed per query. The default sort order is ascending.
58
58
59
59
## Return types
60
60
@@ -70,11 +70,11 @@ Return type depends on first argument (expression). If input argument is string
70
70
71
71
## Remarks
72
72
73
-
`STRING_AGG` is an aggregate function that takes all expressions from rows and concatenates them into a single string. Expression values are implicitly converted to string types and then concatenated. The implicit conversion to strings follows the existing rules for data type conversions. For more information about data type conversions, see [CAST and CONVERT](../../t-sql/functions/cast-and-convert-transact-sql.md).
73
+
`STRING_AGG` is an aggregate function that takes all expressions from rows and concatenates them into a single string. Expression values are implicitly converted to string types and then concatenated. The implicit conversion to strings follows the existing rules for data type conversions. For more information about data type conversions, see [CAST and CONVERT](cast-and-convert-transact-sql.md).
74
74
75
75
If the input expression is type **varchar**, the separator can't be type **nvarchar**.
76
76
77
-
Null values are ignored and the corresponding separator isn't added. To return a place holder for null values, use the `ISNULL` function as demonstrated in [example B](#b-generate-list-of-names-separated-with-comma-without-null-values).
77
+
Null values are ignored and the corresponding separator isn't added. To return a place holder for null values, use the `ISNULL` function as demonstrated in [example B](#b-generate-list-of-middle-names-separated-with-comma-without-null-values).
78
78
79
79
`STRING_AGG` is available in any compatibility level.
`NULL` values found in `name` cells aren't returned in the result.
116
116
117
117
> [!NOTE]
118
-
> If using the [!INCLUDE [ssManStudioFull](../../includes/ssmanstudiofull-md.md)] Query Editor, the **Results to Grid** option can't implement the carriage return. Switch to **Results to Text** to see the result set properly.
119
-
> Results to Text are truncated to 256 characters by default. To increase this limit, change the **Maximum number of characters displayed in each column** option.
118
+
> If you use the [!INCLUDE [ssManStudioFull](../../includes/ssmanstudiofull-md.md)] Query Editor, the **Results to Grid** option can't implement the carriage return. Switch to **Results to Text** to see the result set properly. Results to Text are truncated to 256 characters by default. To increase this limit, change the **Maximum number of characters displayed in each column** option.
120
119
121
-
### B. Generate list of names separated with comma without `NULL` values
120
+
### B. Generate list of middle names separated with comma without NULL values
122
121
123
-
The following example replaces null values with 'N/A' and returns the names separated by commas in a single result cell.
122
+
The following example replaces `NULL` values with `N/A` and returns the names separated by commas in a single result cell.
124
123
125
124
```sql
126
125
USE AdventureWorks2022;
127
126
GO
128
127
129
-
SELECT STRING_AGG(CONVERT (NVARCHAR (MAX), ISNULL(FirstName, 'N/A')), ',') AS csv
128
+
SELECT STRING_AGG(CONVERT (NVARCHAR (MAX), ISNULL(MiddleName, 'N/A')), ',') AS csv
@@ -163,7 +162,7 @@ Rob Walters (Dec 29 2001 12:00AM)
163
162
```
164
163
165
164
> [!NOTE]
166
-
> If using the Management Studio Query Editor, the **Results to Grid** option can't implement the carriage return. Switch to **Results to Text** to see the result set properly.
165
+
> If you use the [!INCLUDE [ssManStudioFull](../../includes/ssmanstudiofull-md.md)] Query Editor, the **Results to Grid** option can't implement the carriage return. Switch to **Results to Text** to see the result set properly. Results to Text are truncated to 256 characters by default. To increase this limit, change the **Maximum number of characters displayed in each column** option.
0 commit comments