Skip to content

Commit 2a4f994

Browse files
committed
dynamic and group by
1 parent cac11a0 commit 2a4f994

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

articles/synapse-analytics/sql-data-warehouse/sql-data-warehouse-develop-dynamic-sql.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Using dynamic SQL
3-
description: Tips for using dynamic SQL in Azure SQL Data Warehouse for developing solutions.
3+
description: Tips for development solutions using dynamic SQL in Synapse SQL pool.
44
services: synapse-analytics
55
author: XiaoyuMSFT
66
manager: craigg
@@ -13,12 +13,16 @@ ms.reviewer: igorstan
1313
ms.custom: seo-lt-2019
1414
---
1515

16-
# Dynamic SQL in SQL Data Warehouse
17-
Tips for using dynamic SQL in Azure SQL Data Warehouse for developing solutions.
16+
# Dynamic SQL in Synapse SQL pool
17+
Tips for development solutions using dynamic SQL in SQL pool.
1818

1919
## Dynamic SQL Example
2020

21-
When developing application code for SQL Data Warehouse, you may need to use dynamic sql to help deliver flexible, generic, and modular solutions. SQL Data Warehouse does not support blob data types at this time. Not supporting blob data types might limit the size of your strings since blob data types include both varchar(max) and nvarchar(max) types. If you have used these types in your application code to build large strings, you need to break the code into chunks and use the EXEC statement instead.
21+
When developing application code for SQL pool, you may need to use Dynamic SQL to help deliver flexible, generic, and modular solutions. SQL pool doesn't support blob data types at this time.
22+
23+
Not supporting blob data types might limit the size of your strings since blob data types include both varchar(max) and nvarchar(max) types.
24+
25+
If you've used these types in your application code to build large strings, you need to break the code into chunks and use the EXEC statement instead.
2226

2327
A simple example:
2428

@@ -33,7 +37,7 @@ EXEC( @sql_fragment1 + @sql_fragment2 + @sql_fragment3);
3337
If the string is short, you can use [sp_executesql](/sql/relational-databases/system-stored-procedures/sp-executesql-transact-sql) as normal.
3438

3539
> [!NOTE]
36-
> Statements executed as dynamic SQL will still be subject to all TSQL validation rules.
40+
> Statements executed as dynamic SQL will still be subject to all T-SQL validation rules.
3741
>
3842
>
3943

articles/synapse-analytics/sql-data-warehouse/sql-data-warehouse-develop-group-by-options.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Using group by options
3-
description: Tips for implementing group by options in Azure SQL Data Warehouse for developing solutions.
3+
description: Tips for implementing group by options in Synapse SQL pool.
44
services: synapse-analytics
55
author: XiaoyuMSFT
66
manager: craigg
@@ -13,21 +13,21 @@ ms.reviewer: igorstan
1313
ms.custom: seo-lt-2019
1414
---
1515

16-
# Group by options in SQL Data Warehouse
17-
Tips for implementing group by options in Azure SQL Data Warehouse for developing solutions.
16+
# Group by options in Synapse SQL pool
1817

19-
## What does GROUP BY do?
18+
In this article, you'll find tips for implementing group by options in SQL pool.
2019

21-
The [GROUP BY](/sql/t-sql/queries/select-group-by-transact-sql) T-SQL clause aggregates data to a summary set of rows. GROUP BY has some options that SQL Data Warehouse does not support. These options have workarounds.
20+
## What does GROUP BY do?
2221

23-
These options are
22+
The [GROUP BY](/sql/t-sql/queries/select-group-by-transact-sql) T-SQL clause aggregates data to a summary set of rows. GROUP BY has some options that SQL pool doesn't support. These options have workarounds, which are as follows:
2423

2524
* GROUP BY with ROLLUP
2625
* GROUPING SETS
2726
* GROUP BY with CUBE
2827

2928
## Rollup and grouping sets options
30-
The simplest option here is to use UNION ALL instead to perform the rollup rather than relying on the explicit syntax. The result is exactly the same
29+
30+
The simplest option here is to use UNION ALL instead to perform the rollup rather than relying on the explicit syntax. The result is exactly the same.
3131

3232
The following example using the GROUP BY statement with the ROLLUP option:
3333
```sql
@@ -79,11 +79,11 @@ JOIN dbo.DimSalesTerritory t ON s.SalesTerritoryKey = t.SalesTerritor
7979
To replace GROUPING SETS, the sample principle applies. You only need to create UNION ALL sections for the aggregation levels you want to see.
8080

8181
## Cube options
82-
It is possible to create a GROUP BY WITH CUBE using the UNION ALL approach. The problem is that the code can quickly become cumbersome and unwieldy. To mitigate this, you can use this more advanced approach.
82+
It is possible to create a GROUP BY WITH CUBE using the UNION ALL approach. The problem is that the code can quickly become cumbersome and unwieldy. To mitigate this issue, you can use this more advanced approach.
8383

84-
Let's use the example above.
84+
Using the previous example, the first step is to define the 'cube' that defines all the levels of aggregation that we want to create.
8585

86-
The first step is to define the 'cube' that defines all the levels of aggregation that we want to create. It is important to take note of the CROSS JOIN of the two derived tables. This generates all the levels for us. The rest of the code is really there for formatting.
86+
It is important to take note of the CROSS JOIN of the two derived tables. This generates all the levels for us. The rest of the code is there for formatting:
8787

8888
```sql
8989
CREATE TABLE #Cube
@@ -114,7 +114,7 @@ SELECT Cols
114114
FROM GrpCube;
115115
```
116116

117-
The following shows the results of the CTAS:
117+
The following image shows the results of the CTAS:
118118

119119
![Group by cube](./media/sql-data-warehouse-develop-group-by-options/sql-data-warehouse-develop-group-by-cube.png)
120120

@@ -141,7 +141,7 @@ WITH
141141
;
142142
```
143143

144-
The third step is to loop over our cube of columns performing the aggregation. The query will run once for every row in the #Cube temporary table and store the results in the #Results temp table
144+
The third step is to loop over our cube of columns performing the aggregation. The query will run once for every row in the #Cube temporary table and store the results in the #Results temp table:
145145

146146
```sql
147147
SET @nbr =(SELECT MAX(Seq) FROM #Cube);
@@ -165,7 +165,7 @@ BEGIN
165165
END
166166
```
167167

168-
Lastly, you can return the results by simply reading from the #Results temporary table
168+
Lastly, you can return the results by reading from the #Results temporary table:
169169

170170
```sql
171171
SELECT *
@@ -174,7 +174,7 @@ ORDER BY 1,2,3
174174
;
175175
```
176176

177-
By breaking the code up into sections and generating a looping construct, the code becomes more manageable and maintainable.
177+
By breaking up the code into sections and generating a looping construct, the code becomes more manageable and maintainable.
178178

179179
## Next steps
180180
For more development tips, see [development overview](sql-data-warehouse-overview-develop.md).

0 commit comments

Comments
 (0)