I have a stored procedure witch runs several EXEC commands. As a result it returns more than one table. In SQL Server Report Builder or SQL Server Data Tools (SSDT) I can only access the first table it retrieves from this stored procedure. But I need to access last table, in which contains the merged columns from different tables produced by different stored procedures.
I have tried the hide tables other than the last table, but failed. Is there any suggestions you can offer to solve this problem. I appreciate and thank with all my hearth to whom tries to contribute the solution of my problem.
I found a solution for this problem. It is not quite what I have asked but solves this issiue. Here is the solution:
I have edited all sub-stored procedures that I used to "RETURN 0" to prevent them to give an output. So when I call them from Main stored procedure they have no visible output at the "Results" window. Only the Main stored procedure has a single output. Thus I can use it in Report Builder or SSDT like a normal stored procedure without any more modification.
Related
I have a stored procedure that runs successfully in SQL Server that is not loading anything into the body of the report. There are only 4 parameters to this procedure, 2 varchars and 2 ints.
I have verified the following:
The stored procedure works in SQL Server
The stored procedure works in SSRS when using Query Designer
The stored procedure shows as being executed and completed in SQL Server Profiler
Running what is shown in the SQL Server Profiler does return the expected results
There is no filtering on the table containing the results
There is no visibility restrictions on the table containing the results
The connection to the database is successful using "Test connection" as mentioned here
I have added a second different dataset into the report and it is showing in the body with no problems.
I have recompiled the procedure as mentioned here and it is still not showing in the report.
There are no multi valued parameters, so this answer is mostly irrelevant.
We are not using Visual Studio, so there is no .DATA files like mentioned here
However for the life of me, I can not get anything from this stored procedure to show up in the body of the report.
Due to legal reasons, the stored procedure cannot be posted in this question as it was part of a software our company is using. We have permission from them to use the procedure to make the SSRS Report for our needs.
Further diagnostics and logging are always useful.
You could have the procedure log additional data to a dedicated table for review later.
Useful data would be that which is related to the user's session based on ##spid and the system views sys.dm_exec_sessions, sys.dm_exec_requests, sys.dm_exec_input_buffer() such as statement start time, any blocking spids, wait_types. Also check the connection level properties are consistent and as expected eg quoted_identifier, ansi-settings etc.
You could also log information about the executing queries such as Rows Affected ##rowcount and the values of any parameters or intermediate values.
Firstly some background on the environment..
RDL's are designed in Report Builder 3.0 (The pre-2016 one).
RDL's are hosted on what appears to be an SSRS 2014 Reporting Services server (Reason why I am saying appears to be is because the alias of the Report Manager and Web Service URL is "SSRS_2014" (And the DBA's told me so)).
Our database server is either running SQL Server 2014 or 2016. I am running SQL Server 2017 on my workstation.
The problem:
I have an SSRS report data set that retrieves information from a very standard stored procedure. Recently I had to change one line of code and add a column related to this change to the result set. Stored procedure works as expected when testing it in SSMS Query Analyser. Here’s an excerpt of the intended results:
But after refreshing the dataset (which adds the new column) the dataset now returns inconsistent values under two columns for all the records returned whilst the stored procedure that retrieves the data is returning values when I run it in SSMS. Even when I run it in Query Designer it still returns inconsistent values.
Here’s a screenshot:
This is not a shared data set and from what I can gather the report does not have any caching applied. When trying to see if there is, or when trying to setup caching the Report Manager returns the following error:
An error occurred within the report server database. This may be due to a connection failure, timeout or low disk condition within the database. (rsReportServerDatabaseError)
Get Online Help For more information about this error navigate to the report server on the local server machine, or enable remote Errors.
As below:
This behaviour is occurring even under the following circumstances:
I deleted and added the data set.
I deleted and added the data source.
I created a new data source.
I created a new RDL.
I created a copy of the stored procedure (Renamed slightly).
I added copies of these columns (Renamed slightly) to the stored procedure (They behave the same).
Fiddled with the “Use single transaction when processing the queries” option (Was off).
The clinchers:
(Bear in mind that the stored procedure returns the data correcting in SSMS).
- When I hard-code the values in the stored procedure, these values appear when executing the stored procedure via SSMS Query Analyser but not when running it via Query Designer (Same inconsistent values).
- I have another (summary) report that obtains data from this stored procedure (Embedded) via another procedure. That report returns the data correctly.
- I tried to create a second stored procedure that executes this stored procedure (Similarly to what the “summary” one does) and it still misbehaves.
- When I take the script that I use to test the stored procedure in SSMS Query Analyser it returns the values! But this is not ideal because the parameters are defined and when I remove those parameters it goes back to normal (mis)behaviour.
I was considering adding a type of snapshot table. Where the stored procedure would first build the data and then do a select from this table to return the data. The problem here is this report is run my multiple users and I do not have the time (3 days before Christmas and I am already on Christmas leave) do go and design a whole snapshot system.
I did a lot of research on the internet yesterday. And went through all suggestions given in the following sites/forums to no avail:
Why is my SSRS report showing old data?
SSRS: field shows correct in query but wrong in report preview
How to clear cache of 1 stored procedure in sql server
https://jazz.net/forum/questions/243993/report-builder-not-showing-updated-data
https://learn.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-freeproccache-transact-sql?view=sql-server-2017
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/e6f86f15-420c-4b64-bc70-01dea93a0995/report-results-and-query-results-returning-different-number-of-rows-why?forum=sqlreportingservices
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/9bc13904-a727-4786-9a11-693570f5f8d4/diable-the-cache-for-all-reports-in-ssrs-2008?forum=sqlreportingservices
And various other ones about caching and so on.
I even got the DBA’s to restart that SSRS server to see if that might refresh any forms of caching.
I also added “WITH RECOMPILE” hint to the stored procedure to no avail.
So I am at a loss… I am at this stage thinking of taking the Stored procedure’s code and running it as an embedded query but that is not best practice.
We are also in the process of handing this project over to another company so I don’t want to leave them this (I have my pride).
I'm using SQL Server 2008 Enterprise. I created a procedure in one database. The procedure is composed of several queries to different databases and the final combined result set is being displayed.
I try to execute it via Excel, so the results will appear automatically in Excel sheet, but I'm getting the error:
The query did not run, or the database table could not be opened. Check the database server or contact your DBA. Make sure the external database is available and hasn't been moved or recognized, then try the operation again
I created a simpler procedure that queries only one database, and the results displayed at the Excel sheet with no issues.
Hence I suspect that, the original procedure failed due to the fact that I'm querying several databases in the procedure, when in the connection details of the "External Data Properties", only one database is mentioned.
My question is - can it be solved? Can I use multiple databases in the procedure and see it in the Excel?
Thanks,
Roni
I transformed the procedure to have Table Variables instead of Temporary tables and I've added "set nocount on" to the beginning of the procedure.
The second action solved the issue.
The first action improved the response time of the procedure.
(Copying key parts of #Roni's answer)
create procedure dbo.xxx
as
set nocount on
...
I have a TON of views that are rather long and dependent/depended on other views. I also have some stored procedures that need to be run weekly and these procedures need to use some of the SQL statements in the views so instead of putting the statements in the procedures I was hoping I could just run the view.
Is that possible? I'll be running these from SQL Server 2008 btw
SQL 101:
A Select statement can be run on a table or view.
So, yes, any code that can access at able can also access a view. Given the necessary permissions.
As I said - this is beginner SQL knowledge. I will add it to my list of interiew questions for junior developers.
A stored procedure is, in essence, nothing more than a canned ad-hoc statement. Yes, it offers many other features but the point is anything you can type in an interactive query window can also be run in a stored procedure.
Views are not restricted to being run in a stored procedure.
Yes you can query tables and views inside your stored procedure.
I'm trying to recreate an access report as a crystal report and I'm having trouble.
Basically, the Access report runs a stored procedure (which returns nothing, but populates tables), then those tables are queried to display the data on the report.
So I'm trying to figure out how to run the procedure with parameters from a crystal report. I've got the second part fine, if I run the procedure manually, then display the report I get the appropriate data.
How can I execute the stored procedure before querying those tables from Crystal Reports???
Have you tried combining the stored procedure and the queries into one stored procedure? Execute the one that populates the tables, and then run the queries that return the data?
Use Visual Studio (Assumes you were using Access, so you may be a Microsoft shop.) to create a form that triggers the stored procedure and then opens the Crystal Report.
This way users don't have to have Crystal Reports installed. Just your app.
Can you get away with a combined Access & Crystal approach?
The Access db prompts the user for parameters and does whatever it needs to get & filter the data from the db.
Crystal generates it's report using the Access db as it's source.
This would be like taking the original Access file, deleting just the report, and recreating just the report in Crystal, using the original Access queries as your source.