SSRS StrComp Function

The SSRS StrComp function is a Text function that performs a string comparison of two fields and returns -1, 0, or 1 based on the result. For instance, if both are the same, it returns 0. If the second argument is greater than the first, it returns -1, and if the first argument is greater than the second, it returns 1. The syntax of the StrComp function to perform the string comparison is shown below.

=StrComp(Fields!ProductDescription.Value, Fields!Product.Value)

To demonstrate the SSRS StrComp function, we use the Employee table below, which has 15 records. The image shows the records in the Table report.

Source Table

SSRS StrComp function Example

For this, let me add a new column to the right side of the FirstName column. Next, right-click the textbox under the FN StrComp Name and choose the Expression. To understand the report, I suggest you refer to the articles on charts, tables, grouping, and format tables in SSRS.

Choose the expression option

It opens the following expression window to perform string comparisons. Here, we used the Previous function to find the previous row. The SSRS StrComp function below will compare the First Name field with the previous row’s value.

=StrComp(Fields!FirstName.Value, Previous(Fields!FirstName.Value))
SSRS StrComp Function expression to perform string comparison on two fields

Similarly, let me create one more new column to the right of the Education. Here, we compare the current Education column against the previous row to check whether they are identical, lower, or higher.

=StrComp(Fields!Education.Value, Previous(Fields!Education.Value))

Please click the preview tab to see the report. For more functions >> Click Here!

SSRS StrComp Function to perform string comparison on two fields preview