Reputation: 287
SELECT Name
FROM Names n
WHERE EXISTS (SELECT NameIDs FROM NameList nl WHERE n.nameID LIKE '%'+nl.nameIDs);
I'm trying to query this table and it only seems to return the first values. Name list is a comma seperated value cell and there can be multiple occurences of it.
I was wondering if anyone could help.
Upvotes: 0
Views: 118
Reputation: 10055
If its comma separated then you need to have the wildcard % after the nl.nameIDs too as the value can occurr anywhere in the middle of the comma separated string.
SELECT Name
FROM Names n
WHERE EXISTS (SELECT NameIDs FROM NameList nl WHERE n.nameID LIKE '%'+nl.nameIDs+'%');
Upvotes: 2
Reputation: 1269773
I think you have the comparison backwards. Try this:
SELECT Name
FROM Names n
WHERE EXISTS (SELECT NameIDs FROM NameList nl WHERE ','+nl.nameIDS+',' like '%,'+n.nameID+',%'
Upvotes: 0