sql - Check to see if a column value is contained by another column -
this question has answer here:
i have table called host in sql follows.
**firstname** **lastname** krishna krishna murthy jithendra jithendra reddy varun varun kumar mahendra varma
if firstname column part of lastname column need create 1 more column values yes/no. output should follows
**firstname** **lastname** **subset** krishna krishna murthy yes jithendra jithendra reddy yes varun varun kumar yes mahendra varma no
any ideas?
you can use
select firstname, lastname, case when lastname '%' + firstname + '%' 'yes' else 'no' end flag host
to results looking for.
if want search cases forename repeated, might want adjust case lastname firstname + ' %'
ensure matches there @ least 2 words, , first in firstname, e.g.
**firstname** **lastname** **subset** bob bobbins no singlename singlename no aaa bbb aaa no
Comments
Post a Comment