I am using SSRS 2008 R2.
If I create a stored procedure that simply has a static SQL statement in it (I have included a highly oversimplified version of my query) and I use that stored procedure in defining a dataset, the fields included in that Select statement are nicely created for me on the dataset.
CREATE PROCEDURE [dbo].[spRptPlanNames] ()
AS
SET NOCOUNT ON
SELECT vwPlan.pkPlan FROM [1ldr_cust].dbo.vwPlan
RETURN
However, if I take that same SQL statement and convert it dynamic SQL and use the EXEC command to execute the query within the stored procedure (I have included a highly oversimplified version of my query) , when I go to create the dataset I can still use that stored procedure and the query designer will do a successful preview on the data, however it will not automatically define all the fields on the dataset object. It essentially has no fields unless I manually create them.
CREATE PROCEDURE [dbo].[spRptPlanNames] (@spldrPlanStatus as varchar(100))
AS
SET NOCOUNT ON
DECLARE @SQLStmt varchar(8000)
Set @SQLStmt = 'SELECT vwPlan.pkPlan FROM [1ldr_cust].dbo.vwPlan'
If rtrim(@spldrPlanStatus) <> 'ALL' and rtrim(@spldrPlanStatus) <> ''
Begin
Set @SQLStmt = @SQLStmt + ' WHERE vwPlan.U_PlanStatusfkPickFromList=' + @spldrPlanStatus
End
EXEC (@SQLStmt)
RETURN
Am I doing something wrong or is this an understood limitation? I was planning on converting over 100 reports to SSRS, using stored procedures, until I discovered this.