Comparing 2 columns in the same table with the "Like" function
Posted
by Vic
on Stack Overflow
See other posts from Stack Overflow
or by Vic
Published on 2010-03-08T18:14:37Z
Indexed on
2010/03/08
18:21 UTC
Read the original article
Hit count: 384
sql
|pattern-matching
I'm trying to come up with a way to query the values in two different columns in the same table where the result set will indicate instances where the value of columnB doesn't contain the value of columnA.
For example, my "Nodes" table contains columns "NodeName" and "DNS".
The values should look similar to the following:
NodeName DNS
Router1 Router1.mydomain.com
I want to run a query to show which rows have a DNS value that does not contain (or begin with) the value of the NodeName field. I think the query should function something similar to the following, but obviously I'm missing something with regard to the use of "Like" in this situation.
SELECT NodeName, DNS
WHERE DNS NOT LIKE 'NodeName%'
I'm using SQL Server 2005, and any suggestions would be greatly appreciated... :)
© Stack Overflow or respective owner