I have a complex scenario for string matching and want input from you guys. I have a table Named Customers. This table contains a field CustomerName varchar. Data in the column is prefixed with Mr. Mrs. Ms. Data could be
Now I need to design a search query that returns me rows of only Couples and in a sequenced manner.
Like Select CustomerName from Customer where ...?? Result needs to be like
Any Idea ?
Thanks in advance for the consideration.
declare @T table(Name varchar(25))
insert into @T values
('Mr. John Brady'),
('Ms. Abraham Lenin'),
('Mrs. John Brady'),
('Mr. Michael King'),
('Mrs. Neil Thomas'),
('Mrs. Michael King')
;with C as
(
select Name,
count(*) over(partition by stuff(Name, 1, charindex(' ', Name), '')) as Cnt
from @T
)
select Name
from C
where Cnt = 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With