Stored Procedures or SQL query which one is better for SSRS report Creation

Bala Narasimha Challa 466 Reputation points
2021-06-21T06:41:17.307+00:00

Hi Team,

which one is better to SSRS report Creation as a source query , Stored Procedures or SQL query and why ?

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.
3,063 questions
0 comments No comments
{count} votes

Accepted answer
  1. Joyzhao-MSFT 15,636 Reputation points
    2021-06-21T09:13:43.107+00:00

    Hi @Bala Narasimha Challa
    Stored procedures (SPs) are a better choice than views, but views are much better than SQL queries embedded in reports.

    Here quote the reply from the external link:
    When you embed a SQL query in a report (or an application or anything outside of the database) you are assuming that all of the objects referenced are not going to change in any way. This is firstly a big assumption (and assumptions are bad) and secondly a crippling restriction on the database owner - they can't change anything because it might break something somewhere.

    When you use an SP or a view to access a database you make the reasonable assumption that the name of the object you are calling (the SP or view) won't change and that any parameter set will remain constant or at least stay compatible. Both approaches hide away the logic of the query from the caller - the logic can be corrected and improved over time without affecting the caller. The entire database can be refactored or even redeisigned as long as the name of the exposed object (and any parameters) remain the same and the caller will never know.

    The advantage of using an SP over a view is that you can do far more. For example it's a good idea to validate that parameter values are within expected ranges. If you have a particularly complex query you can break it down into smaller steps, using temp tables for example. Moving on to very heavy queries you could even do interim maintenance steps in an SP, updating stats for example.

    Here are the advantages and disadvantages of using Stored Procedures, Embedded Queries, and Views in the SSRS Dataset. For more information, please refer to: Pros and Cons: Stored Procedures–vs- Embedded Queries–vs- Views in an SSRS Dataset.
    Hope this helps.
    Best Regards,
    Joy


    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.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Will Faulkner 201 Reputation points
    2021-06-22T14:21:19.83+00:00

    If your query takes a long time to run I'd use a SP; if it's relatively simple then just use an SQL query.

    0 comments No comments

  2. Ken Wilson 0 Reputation points
    2024-04-03T21:08:16.2233333+00:00

    I have actually found the Stored Procs to cause several issues.

    1. tracking down the code to generate the data. Sometimes you end up with
      multiple stored proc calls.. Messy and time consuming when you have to change
      things to improve or change the data being pulled
    2. Regular calls to stored procs actually slowing down things due to regular calls
      rather than just running the query and returning the data. Removing the stored procs speeded up things considerably in several cases
    3. Stored Procs for simple queries.. just a waste of time with nothing to show for it
      and then your stuck back at #1. Most queries are simple if the database design is good.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.