Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

TABLE variable is not working in fabric warehouse

Hello,

 

 

I am using warehouse stored procedure and loading the query results into normal tables instead of temp tables as they are not supported in fabric. I created one table already in my stored proc but to do further more transformations in same stored procedure i dont want to create new table again i want to use either TEMP table or TABLE variable but both are not working in warehouse .

 

 

Is there any other solution is available to load the query results into temporary tables instead of normal tables.

 

 

Regards

Pavan kumar

  • Anonymous's avatar
    Anonymous
    2 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 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.

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous 

     

    Thank you am glad i found an alternative approach to do this. As mentioned above i implemented the CTEs for my requirement and it is working as expected. 

     

    is there any plan to make Temporary tables enhancement in future for warehouse. Any way thanks for the suggestions.

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    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.