CHARINDEX with CASE Function in SQL Server

CharIndex returns the position at which the sequence of character(s) starts and CASE function allows you to check value against multiple criteria.
Ex:

SELECT

CASE CHARINDEX(s.[first name], ss.[first name])
WHEN 0 then ss.[First Name] + ‘ ‘ + ss.[middle name] + ‘ ‘ + ss.[Last Name]
ELSE ‘ NoReports ‘
END        as  Names

FROM NameTable

Leave a Reply