Skip to content

Commit b8c4afa

Browse files
authored
Merge pull request #188033 from Clare-Zheng82/0208-Add_CTE_use_method_to_SQL_connector_docs
Add a Tip about CTE in SQL connector docs
2 parents 63bd2b6 + 26e66b6 commit b8c4afa

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

articles/data-factory/connector-azure-sql-database.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.service: data-factory
88
ms.subservice: data-movement
99
ms.topic: conceptual
1010
ms.custom: synapse
11-
ms.date: 01/28/2022
11+
ms.date: 02/08/2022
1212
---
1313

1414
# Copy and transform data in Azure SQL Database by using Azure Data Factory or Azure Synapse Analytics
@@ -756,6 +756,18 @@ Settings specific to Azure SQL Database are available in the **Source Options**
756756

757757
**Query**: If you select Query in the input field, enter a SQL query for your source. This setting overrides any table that you've chosen in the dataset. **Order By** clauses aren't supported here, but you can set a full SELECT FROM statement. You can also use user-defined table functions. **select * from udfGetData()** is a UDF in SQL that returns a table. This query will produce a source table that you can use in your data flow. Using queries is also a great way to reduce rows for testing or for lookups.
758758

759+
> [!TIP]
760+
> The [common table expression (CTE)](/sql/t-sql/queries/with-common-table-expression-transact-sql?view=sql-server-ver15&preserve-view=true) in SQL is not supported in the mapping data flow **Query** mode, because the prerequisite of using this mode is that queries can be used in the SQL query FROM clause but CTEs cannot do this.
761+
>To use CTEs, you need to create a stored procedure using the following query:
762+
>```SQL
763+
> CREATE PROC CTESP @query nvarchar(max)
764+
> AS
765+
> BEGIN
766+
> EXECUTE sp_executesql @query;
767+
> END
768+
>```
769+
>Then use the **Stored procedure** mode in the source transformation of the mapping data flow and set the `@query` like example `with CTE as (select 'test' as a) select * from CTE`. Then you can use CTEs as expected.
770+
759771
**Stored procedure**: Choose this option if you wish to generate a projection and source data from a stored procedure that is executed from your source database. You can type in the schema, procedure name, and parameters, or click on Refresh to ask the service to discover the schemas and procedure names. Then you can click on Import to import all procedure parameters using the form ``@paraName``.
760772

761773
:::image type="content" source="media/data-flow/stored-procedure-2.png" alt-text="Stored procedure":::

articles/data-factory/connector-azure-sql-managed-instance.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.topic: conceptual
88
ms.author: jianleishen
99
author: jianleishen
1010
ms.custom: synapse
11-
ms.date: 01/28/2022
11+
ms.date: 02/08/2022
1212
---
1313

1414
# Copy and transform data in Azure SQL Managed Instance using Azure Data Factory or Synapse Analytics
@@ -765,6 +765,18 @@ The below table lists the properties supported by Azure SQL Managed Instance sou
765765
| Batch size | Specify a batch size to chunk large data into reads. | No | Integer | batchSize |
766766
| Isolation Level | Choose one of the following isolation levels:<br>- Read Committed<br>- Read Uncommitted (default)<br>- Repeatable Read<br>- Serializable<br>- None (ignore isolation level) | No | <small>READ_COMMITTED<br/>READ_UNCOMMITTED<br/>REPEATABLE_READ<br/>SERIALIZABLE<br/>NONE</small> |isolationLevel |
767767

768+
> [!TIP]
769+
> The [common table expression (CTE)](/sql/t-sql/queries/with-common-table-expression-transact-sql?view=sql-server-ver15&preserve-view=true) in SQL is not supported in the mapping data flow **Query** mode, because the prerequisite of using this mode is that queries can be used in the SQL query FROM clause but CTEs cannot do this.
770+
>To use CTEs, you need to create a stored procedure using the following query:
771+
>```SQL
772+
> CREATE PROC CTESP @query nvarchar(max)
773+
> AS
774+
> BEGIN
775+
> EXECUTE sp_executesql @query;
776+
> END
777+
>```
778+
>Then use the **Stored procedure** mode in the source transformation of the mapping data flow and set the `@query` like example `with CTE as (select 'test' as a) select * from CTE`. Then you can use CTEs as expected.
779+
768780
#### Azure SQL Managed Instance source script example
769781

770782
When you use Azure SQL Managed Instance as source type, the associated data flow script is:

articles/data-factory/connector-sql-server.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.service: data-factory
88
ms.subservice: data-movement
99
ms.topic: conceptual
1010
ms.custom: synapse
11-
ms.date: 01/28/2022
11+
ms.date: 02/08/2022
1212
---
1313

1414
# Copy and transform data to and from SQL Server by using Azure Data Factory or Azure Synapse Analytics
@@ -640,6 +640,18 @@ The below table lists the properties supported by SQL Server source. You can edi
640640
| Batch size | Specify a batch size to chunk large data into reads. | No | Integer | batchSize |
641641
| Isolation Level | Choose one of the following isolation levels:<br>- Read Committed<br>- Read Uncommitted (default)<br>- Repeatable Read<br>- Serializable<br>- None (ignore isolation level) | No | <small>READ_COMMITTED<br/>READ_UNCOMMITTED<br/>REPEATABLE_READ<br/>SERIALIZABLE<br/>NONE</small> |isolationLevel |
642642

643+
> [!TIP]
644+
> The [common table expression (CTE)](/sql/t-sql/queries/with-common-table-expression-transact-sql?view=sql-server-ver15&preserve-view=true) in SQL is not supported in the mapping data flow **Query** mode, because the prerequisite of using this mode is that queries can be used in the SQL query FROM clause but CTEs cannot do this.
645+
>To use CTEs, you need to create a stored procedure using the following query:
646+
>```SQL
647+
> CREATE PROC CTESP @query nvarchar(max)
648+
> AS
649+
> BEGIN
650+
> EXECUTE sp_executesql @query;
651+
> END
652+
>```
653+
>Then use the **Stored procedure** mode in the source transformation of the mapping data flow and set the `@query` like example `with CTE as (select 'test' as a) select * from CTE`. Then you can use CTEs as expected.
654+
643655
#### SQL Server source script example
644656

645657
When you use SQL Server as source type, the associated data flow script is:

0 commit comments

Comments
 (0)