Forum Discussion
TABLE variable is not working in fabric warehouse
- Anonymous2 years ago
Hi,Anonymous
I am glad to help you.
According to your description, you want to create temporary tables in the warehouse, but you realize that the warehouse currently restricts the use of TEMP. I looked into this and found that your concern is correct, creating temporary tables is one of the known limitations of Fabric warehouse.URL: Tables in data warehousing - Microsoft Fabric | Microsoft Learn
Below I provide some suggestions that I hope will help you
1. Use subqueries (derived tables) in your SQL statements.
If possible, instead of creating a temporary table, use a subquery, you can use the derived table directly in the query without creating a temporary table.
like this:SELECT dt.Column1, dt.Column2 FROM ( SELECT Column1, Column2 FROM YourTable WHERE Condition = 'Value' ) AS dt WHERE dt.Column2 = 'Value02'2.Use Common Table Expression(CTE)
CTE can be used to generate temporary result sets defined within the execution of a single SELECT, INSERT, UPDATE or DELETE statement. CTE can simplify the complexity of the query, if your data source supports the use of CTE, then it is a good alternative
like this:WITH TempResults AS ( SELECT Column1, Column2 FROM YourTable WHERE Condition = 'Value' ) SELECT * FROM TempResults WHERE Column2 = 'Value02'Here is the documents on CTE that I hope you find helpful
URL:
WITH common_table_expression (Transact-SQL) - SQL Server | Microsoft Learn
Common table expression (CTE) | Databricks on AWSI hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,Anonymous
I am glad to help you.
According to your description, you want to create temporary tables in the warehouse, but you realize that the warehouse currently restricts the use of TEMP. I looked into this and found that your concern is correct, creating temporary tables is one of the known limitations of Fabric warehouse.
URL: Tables in data warehousing - Microsoft Fabric | Microsoft Learn
Below I provide some suggestions that I hope will help you
1. Use subqueries (derived tables) in your SQL statements.
If possible, instead of creating a temporary table, use a subquery, you can use the derived table directly in the query without creating a temporary table.
like this:
SELECT dt.Column1, dt.Column2
FROM (
SELECT Column1, Column2
FROM YourTable
WHERE Condition = 'Value'
) AS dt
WHERE dt.Column2 = 'Value02'
2.Use Common Table Expression(CTE)
CTE can be used to generate temporary result sets defined within the execution of a single SELECT, INSERT, UPDATE or DELETE statement. CTE can simplify the complexity of the query, if your data source supports the use of CTE, then it is a good alternative
like this:
WITH TempResults AS (
SELECT Column1, Column2
FROM YourTable
WHERE Condition = 'Value'
)
SELECT *
FROM TempResults
WHERE Column2 = 'Value02'
Here is the documents on CTE that I hope you find helpful
URL:
WITH common_table_expression (Transact-SQL) - SQL Server | Microsoft Learn
Common table expression (CTE) | Databricks on AWS
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.