2
votes

I created a report in SSRS using a query with parameters and it worked fine. But I decided to use a stored procedure instead so that if ever there is any changes needed, it would only need to be applied to SSMS and not both SSMS and the query in SSRS.

So I created a stored procedure like seen below:

USE [Some_Database]

GO

CREATE PROCEDURE MyReport 

AS

DECLARE @p_ServerName nvarchar(10) = 'all'
DECLARE @p_Env        nvarchar(10) = 'all'
DECLARE @p_EnvCat     nvarchar(10) = 'all'

SELECT DISTINCT <rest of my query...>

This is a greatly shortened version of what I am using but the ordering of the keywords is accurate. When I preview the report it in SSRS I get my No Rows Message.

Can anyone see what I did wrong in the creation of the stored procedure?

Also does using a stored procedure require different parameter setup in SSRS than if using a query?

Cheers.

UPDATE: After putting paramters between CREATE and AS and removing DECLARE, it works in SSRS for specific values but when I choose "ALL" it does not.

Any ideas?

2
Did you intend those to be input variables?HLGEM
yea I am using those parameters. It worked when I used a query in SSRScholoboy

2 Answers

1
votes

The only thing I can think of is perhaps with where the parameters are positioned. If there are params being passed in from an outside source, like from a user inputing them in reporting services or something, then they need to be declared before the AS statement like so:

USE [CRCIVR]
GO
Create Proc dbo.[spFrontTileExceptionsData]  
(
    @userid as int,
    @companyid as int,
    @exceptioncodes as varchar
)        
AS
Begin     

That is all I can think of without seeing the rest of the code though. It could also be something within reporting services itself.

1
votes

You'll want to make the stored procedure accept input parameters, in order for SSRS to send them in. If you DECLARE parameters within the proc, those are otherwise 'hidden' to SSRS. Using your example, it'd be something like this:

USE [Some_Database]

GO

CREATE PROCEDURE MyReport 
   @p_ServerName NVARCHAR(10) = 'all',
   @p_Env NVARCHAR(10) = 'all',
   @p_EnvCat NVARCHAR(10) = 'all'
AS

SELECT DISTINCT <rest of my query...>