I am trying to do a CASE
statement that combines two columns that are not alike. However, these two columns are names and the name could actually be the same except it might sometimes contain a suffix. So for instance, I want to bring back the following:
LastName1 | LastName2
------------------------
Ross | Ross, Jr.
Lee | Lee
Smith | Collins
Martin | Martin
Pierce, Sr. | Pierce
So, my statement looks like this:
SELECT CASE WHEN LastName1 <> LastName2 THEN LastName1 + ', ' + LastName2 ELSE LastName1 END AS LastName
This returns the results as such:
LastName
---------
Ross, Ross, Jr.
Lee
Smith, Collins
Martin
Pierce, Pierce, Sr.
But I would like to use a NOT LIKE
(or something similar) and if the first few characters of the LastName1
column are similar to LastName2
, only bring back one instance of the name. So my result set would look like:
LastName
---------
Ross
Lee
Smith, Collins
Martin
Pierce