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 2012 Forums
 Transact-SQL (2012)
 How to see if something contains a value part2

Author  Topic 

tshaw20832
Starting Member

10 Posts

Posted - 2014-05-08 : 18:12:33
All I forgot a bit of information.

I have two columns with the following:

Column A Column B
aaa-12345-er45-y1 12345
www-12344-er56-p1 12344

How would I compare the two and get a yes that information in column B contains values in Column A

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-05-08 : 18:24:13
select case when columnA like '%' + columnB + '%' then 'yes' else 'no' end
from yourTable

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-05-09 : 05:45:38
or this

select PATINDEX('%' + columnB + '%',ColumnA) > 0 then 'yes' else 'no' end
from yourTable


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

tshaw20832
Starting Member

10 Posts

Posted - 2014-05-09 : 07:56:10
Thank you very much everyone. TGIF
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-05-09 : 12:30:22


Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -