Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Comparing strings

Author  Topic 

kennyb
Starting Member

5 Posts

Posted - 2010-12-16 : 22:43:18
I have two columns TodaysOwner and TodaysTrainer:

TodaysTrainer------------TodaysOwner
CARROLL JOSIE------------DONVER STABLE
SIDER ALVIN--------------C & R STABLE LLC & FRANK ADOLPH LLC
CULOTTA RAY--------------LORI CULOTTA
CORMIER DONALD-----------HOPE LAMARCHE
VAZQUEZ GAMALIEL---------MICHAEL J GILL
CORRADO ROBERT-----------CORRADO ROBERT MARX JOSEPH
BINDNER WALTER M JR------MASON C RUDD
CRIOLLO MANUEL-----------SILVER DIAMOND THOROUGHBREDS INC
THOMPSON YVETTE----------YVETTE THOMPSON

When I run a SELECT statement with the WHERE clause TodaysTrainer = TodaysOwner, it only works when the names are exact and in the same order. As you can see, sometimes there are also multiple owners.

Can someone please help me construct a where clause that would take the first 5 letters of the string in the TodaysTrainer column and return true if it was like the string in the TodaysOwner column?

I think this would be accurate enough for what I want. It would have picked up Culotta, Corrado, and Thompson in the above sample data.

Thanks in advance

KB

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2010-12-16 : 23:02:52
WHERE TodaysOwner like '%' + LEFT(TodaysTrainer,5) + '%'



Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page

kennyb
Starting Member

5 Posts

Posted - 2010-12-16 : 23:40:34
Wow DataGuru,

I'm amazed and so thankful. It works perfectly for my needs.

Your moniker is sooo right on.

KB
Go to Top of Page
   

- Advertisement -