SQLTeam.com | Weblogs | Forums

Matching string formats based on condition -- SQL Server

This is a rather complicated scenario, but I will do my best to explain the problem. I am working with a column of strings (column A). I need to be able to search two of the other columns (columns B and C - also string columns) in the dataset for a string which matches the format of another string already in column A ONLY IF this entry satisfies a given condition.

Specifically, I need code that will return a string from either column B or column C only if there is a string of the exact same format already populated in column A where column B = column C.

Please let me know if I can clarify anything further.



Sample data would really help clarify things

Declare @sample(
Columna varchar(50),
Columnb varchar(50),
Columnc varchar(50)

Insert into @sample
Select 'vader', 'luke', 'scith'