简体   繁体   中英

SSRS Report Using Stored Procedure

I am working with an SSRS Report that uses a stored procedure.

The stored procedure [after the Use ... Set ANSI NULLS On ] starts with ALTER PROCEDURE ...

While I can understand the SQL in a stored procedure, I have never used one in an SSRS Report [I only use 'straight' SQL statements].

When I use SQL as my Dataset, I can copy that SQL into SSMS and run it and see the data it returns.

With this stored procedure, how do I execute it in SSMS to see the data it returns? The stored procedure has a sample 'EXEC ...' statement with all the parameters populated ... but when I run that - no data is returned.

The SSRS report runs fine, but I want to be able to work with the stored procedure in SSMS and see the data it is returning. My goal is to be able to run the stored procedure in SSMS and then tweak it.

How do I work with this stored procedure in SSMS so I can look at the output?

The stored procedure [after the Use ... Set ANSI NULLS On] starts with ALTER PROCEDURE ...

That's the Alter Procedure script. Use this to edit a stored procedure.

In other words, edit the SQL code you want to optimize, then run the whole script to save the changes.


How do I work with this stored procedure in SSMS so I can look at the output?

In SSMS use the syntax for stored procedures:

EXEC myspname paramter1, parameter2, param...

Where parameter1, parameter2, etc. are the parameters described in the ALTER Procedure script, directly after the ALTER PROCEDURE myspname . Parameters are preceded by the @ symbol.

As you type-in the EXEC procedure command pop-up hints should appear describing the parameter.

Without knowing the code to the stored procedure, it could be doing any number of things based on what is passed to it by parameter. A stored procedure can do DDL and DML queries, and does not necessarily have to select anything at all for output.

If you just want to execute the procedure in SSMS, locate it in the object browser ([DatabaseName]/Programmability/Stored Procedures). RIght-click the procedure and select 'Execute Stored Procedure'

在此处输入图片说明

Fill in the parameters and click OK and a script will be generated to run the procedure.

在此处输入图片说明

It's a bit overkill but at least everything is there and you can run it whenever you like.

If you want to edit the proc, right-click and choose modify, a new script will be created (the ALTER PROCEDURE script you mentioned). Make changes as required, run the script and that will modify the procedure, then execute the procedure to see the results.

Of course it would be safer to make a copy and edit that, you can also just run the body of the stored proc by commenting out the ALTER PROCEDURE statement until you are happy with it but you may have to declare and variables that are normally passed in as parameters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM