简体   繁体   English

如何使用根据参数返回数据的过程创建SSRS报告

[英]How to create SSRS report using procedure that returns data based on parameter

I have a stored procedure that returns number of columns based on parameter @SearchType. 我有一个存储过程,该过程根据参数@SearchType返回列数。 So first it checks what is the parameter value, then SELECT statement returns data. 因此,首先检查什么是参数值,然后SELECT语句返回数据。

My problem is how can I use this procedure in SSRS? 我的问题是如何在SSRS中使用此过程? It doesn't bring me any columns so I can add it to a table or matrix. 它不带任何列,因此可以将其添加到表或矩阵中。

In SSMS the procedure works fine. 在SSMS中,该程序运行正常。 There gotta be a work around for that. 必须为此解决。

Thanks 谢谢

在此处输入图片说明

ALTER PROCEDURE dbo.RPT_spLoadUserOpenTasks
      (
        @UserGUID varchar(8000) = NULL,
        @NoteStoreType INT = NULL,
        @DateFrom datetime = NULL,
        @DateTo datetime =NULL,
        @LineGUID varchar(8000) = NULL
      ) 

AS
 IF @SearchType = 0
 BEGIN 
       SELECT DISTINCT 
            TOP 100 PERCENT 
                Column1,
                Column2,
                Column3
                --other columns
         FROM 
                  dbo.tblNoteEntities  (nolock) 
           --some other JOINs here 
         WHERE tq.LineGuid IN (SELECT * FROM @LineTable)
                AND               
                  (@UserGUID IS NULL OR tblNoteRecipients.UserGUID = @UserGUID) 
             ORDER BY  Column1
      RETURN
END
--------------------------------------------------------------------------------
if @SearchType = 1  --eq and eq access 
BEGIN 
SELECT DISTINCT 
            TOP 100 PERCENT 
                Column4,
                Column5,
                Column6
         FROM 
                  dbo.tblNoteEntities  (nolock) 
           --some other JOINs here 
         WHERE tq.LineGuid IN (SELECT * FROM @LineTable)
                AND               
                  (@UserGUID IS NULL OR tblNoteRecipients.UserGUID = @UserGUID) 
             ORDER BY  Column1
      RETURN
END
--------------------------------------------------------------------------------
if @SearchType = 3 --And so on 

You have to define the columns of your query outputs manually in the dataset. 您必须在数据集中手动定义查询输出的列。

Since column names and number is not static try to do so by having each query to return the same number of columns having empty data for columns not required. 由于列名和列号不是静态的,请尝试通过使每个查询返回相同数量的列(具有不需要的列的空数据)来实现。

For each value of your parameter, create the table containing the required columns and set table visibility depending the selected value of the parameter (for example if parameter has 3 values you have to create 3 tables but only one will be visible each time). 对于参数的每个值,创建包含所需列的表,并根据参数的选定值设置表可见性(例如,如果参数具有3个值,则必须创建3个表,但每次只能显示一个表)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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