Should aggregates be created in a temp table or CTE or there is any better way of doing it ?

Mudassar A 481 Reputation points
2020-09-15T15:48:58.51+00:00

I want to know if aggregates should be created in a TEMP table or CTE in a SP ?

The requirement is to plot aggregated data with detail dimension data . I wanted to know if I m using SSRS as the front end and SQL server 2016 as the back end .Should I created my aggregates in a temp table or CTE and then join them with the dimension dataset in SP before plotting them on SSRS tabular report ?

I have 30 dimensions and 20 measures .The 20 new measures have to be computed and added to an existing SSRS report .

My data size is 38k records and can grow up to max 70K records.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,642 questions
SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,790 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,547 questions
0 comments No comments
{count} votes

Accepted answer
  1. Lukas Yu -MSFT 5,816 Reputation points
    2020-09-16T01:46:08.853+00:00

    With current information, it is hard to say to use which method. Both method is supported in SSRS dataset.

    Personally, I tend to use temp table for performance , since your dataset is relatively big.


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Guoxiong 8,126 Reputation points
    2020-09-15T15:59:24.037+00:00

    I think you can create some views to achieve it.

    1 person found this answer helpful.

  2. tibor_karaszi@hotmail.com 4,301 Reputation points
    2020-09-15T17:19:12.913+00:00

    Is it from a performance perspective you ask?

    If so, then it is impossible for us to say.

    Sometimes a cte is better since sql server can make "one query" of it all.

    But sometimes it is better to break up one gigant query into several smaller queries, the results stored in temp tables, so the optimizer don't "choke" on the gigant query.

    1 person found this answer helpful.

  3. Jeffrey Williams 1,886 Reputation points
    2020-09-15T20:52:45.333+00:00

    If the choice is between a temp table and a CTE - and this is for SSRS - then a CTE is the better option. SSRS and temp tables don't mix well - and can cause some issues when developing the reports.

    If using a CTE causes performance issues then you may need to resort to temp tables and figuring out how to make sure SSRS works with that procedure.

    1 person found this answer helpful.
    0 comments No comments