userid in
(CASE WHEN @userid <>''
THEN cast(@userid as varchar(20))
ELSE userid END)
userid is string but your case statement returns a varchar hence the issue.
You need to ensure your case statement returns an int, so cast the
WHEN
clause output into an int.