Cast is preferred over Convert, Cast is based on the SQL-92 standard. While Cast was meant to convert hex values to binary, it does work for our string values since we are only comparing, similar to a hash value. The SQL Statement is basically a standard select, we use Cast in the where clause. When a parameter is passed to the stored procedure, the parameter is converted and compared to the converted sTest field value. If the two values match, including case, the record is selected.
Lets walk through the stored procedure.
With that done, lets run the stored procedure with aba for the parameter. Since two of the three records are aba, those two are returned. Next run the stored procedure with the aBa parameter, now only the one aBa record is returned. Last use ABA for the parameter, none of the records match so no records are returned.