简体   繁体   English

在SSRS中查询存储过程

[英]Query to Stored Procedure in SSRS

I am getting data from a table and I am writing off to the report through a stored procedure. 我正在从表中获取数据,并且正在通过存储过程将其写到报告中。 In the reporting part it has to show the results by users defined date. 在报告部分中,必须按用户定义的日期显示结果。

Eg: 例如:

Today - should show today's results only
Yesterday - should show Yesterday's results only 

How should I declare the values in a stored procedure and how can I implement in ssrs reporting part? 如何在存储过程中声明值,如何在ssrs报告部件中实现?

My CreateDate column keeps changing has the table ( FailedJobsInfo ) gets updated. 我的CreateDate列不断变化,以更新表( FailedJobsInfo )。

Here is my stored procedure: 这是我的存储过程:

ALTER PROCEDURE [dbo].[FailedJobsInfo] 
    @StartDate DATETIME
AS
    SELECT 
      [SQLServer]
      ,[JobName]
      ,[StepName]
      ,[FailureMessage]
      ,[RunDateTime]
      ,[RunDuration]
      ,[CreateDate]
    FROM 
      [dbo].[FailedJobsInfo]
    WHERE  
      CONVERT(varchar(20), CreateDate, 101) = CONVERT(varchar(20), GETDATE(), 101)

Starting from your SSRS Report. 从您的SSRS报告开始。

1) Create a Parameter with Labels and Values as below 1)创建带有标签和值的参数,如下所示

 Label        Value
 Today          0
Yesterday       1

2) Make your Procedure to accept an INT Parameter, If user selects Today it will pass zero 0 to stored procedure, if user selects Yesterday it will pass procedure 1 to procedure and this Integer value will be subtracted from your getdate() value avoiding time part. 2)使你的程序来接受INT参数,如果用户选择Today它会通过零0到存储过程中,如果用户选择Yesterday它会通过步骤1至步骤和该Integer值将从你的GETDATE()值避免时间中减去部分。 you will need to do as follow : 您将需要执行以下操作:

ALTER PROCEDURE [dbo].[FailedJobsInfo] 
    @StartPeriod INT
AS
BEGIN
  SET NOCOUNT ON;

    SELECT 
      [SQLServer]
      ,[JobName]
      ,[StepName]
      ,[FailureMessage]
      ,[RunDateTime]
      ,[RunDuration]
      ,[CreateDate]
    FROM 
      [dbo].[FailedJobsInfo]
    WHERE  
      CAST(CreateDate AS DATE) = CAST(GETDATE() AS DATE) - @StartPeriod  --<-- 
END

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

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