Friday 27 January 2017

Date Range Validation (Start Date and End Date) in SSRS

      DateRange Validation or in other words Start Date and End Date validation is not a inbuilt validation in SSRS, so we require to implement VB script here. Follow the below steps :


1) Lets say we have a reporting table with four columns whose filters have parameters @StartDate and @EndDate :


2) Now Go to Menu → Report → Report Properties → Code
    And put the function code as below :



Function Script :



Function CheckDateParameters(StartDate as DateTime , EndDate as DateTime) as Boolean 
Dim RetValue As Boolean 
RetValue = "False" 
if(StartDate < EndDate) then 
RetValue = "True" 
else 
RetValue = "False" 
end if 
Return RetValue 
End Function 




3) Add a parameter @ValidateDateRange of Boolean type, make it hidden then go to its Default Values section, check radio button Specify Values and open exepression and put the code as  =Code.CheckDateParameters(Parameters!StartDate.Value, Parameters!EndDate.Value)




4) Add a Text Box and write the error message as "Start Date cannot be greater than End Date !" in its text.


5) Now go to the Tablix Properties of the original table :


6) Go to Visibility Section, check last radio button "Show or Hide on .." and put the expression =IIF(Parameters!ValidateDateRange.Value,True,False) :




7) Similarly go to the Visibility Section of Error Message TextBox and put the expression as




8) So now if we run the report with Start Date greater than End Date then we get the below ouput :



and its done.



Reference: Govind Badkur(http://sqlserver20.blogspot.com)

No comments:

Post a Comment