Report Parameter validation in ssrs report

后端 未结 3 560
一个人的身影
一个人的身影 2020-12-21 10:37

I have created one SSRS report having begin date and end date. If I provide end date< start date it will execute the report as shown in the image

相关标签:
3条回答
  • 2020-12-21 11:16

    I'm answering this to chip in another possible solution when working with SQL/Server. If you just want to throw an error then simply amend your query SQL to raise an error on the SQL/Server side by adding something like this to the top of your SQL...

    IF @ParEndDate < @ParStartDate
    BEGIN
       RAISERROR('Please check the start date and end date provided', 16, 1);
       RETURN;
    END;
    

    The query won't run and the error message will be displayed in the report body.

    0 讨论(0)
  • 2020-12-21 11:26

    Ciarán, thanks for your suggestion, but the problem with it is you are still hitting the database. I came across these two links that I found a little more helpful in explaining how to validate in SSRS without hitting the database.

    This link shows everything except it's not clear how to use the validation parameter in conjunction with the stored proc.: http://geekswithblogs.net/Compudicted/archive/2012/08/14/validate-ssrs-report-input-parameters-the-proper-way.aspx

    This link clears up how to use the validation parameter with the stored proc.: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/01b37f60-9048-4c54-8d54-574b5fc71de5/how-to-call-a-stored-proc-conditionally-based-on-a-parameter-validation-or-using-a-stored-proc-in?forum=sqlreportingservices

    Added helpful link... I needed to validate using regular expressions and found this link really helpful: https://regex101.com/

    0 讨论(0)
  • 2020-12-21 11:31

    Click Report Menu then Report Properties.
    Go to Code Tab and add similar code as per your requirement:

    Function CheckDateParameters(StartDate as Date, EndDate as Date) as Integer
    Dim msg as String
         msg = ""
         If (StartDate > EndDate)  Then
     msg="Start Date should not be later than End Date"
         End If
         If msg <> "" Then 
     MsgBox(msg, 16, "Report Validation")
     Err.Raise(6,Report)                    'Raise an overflow
         End If
    End Function
    

    And

    Follow the Steps:

    1.) Go the Report Parameters and add a parameter with the datatype is string.

    2.) Check the Hidden checkbox and Allow blank value ckeckbox.

    3.) From Default Values choose Non-Queried radio button and then press the FX button and paste this code.

    =CODE.CheckDateParameters(<parameterStartdate>.Value,<parameterEnddate>.Value)
    

    Then press OK.

    See reference Link:

    Easy Step by Step SSRS Parameter Validation Using Code & Conditional DataSet

    0 讨论(0)
提交回复
热议问题