SQL: Specific LIKE statement

T

Toni

If I need to load all records with name John, than I can use "Where
Name='John'";
If I need to load all records which contains pattern Jo, than I can use
"Where Name like '%Jo%'";

But I need to load all records where field Name is one of the names in
this string: "John is director, Jack is programmer, Jim is Analyst, James is
manager".

So I need to load all fields from table Names where field Name is John,
Jack, Jim and James.

Ho to do that with SQL?
 
B

bruce barker

there are several options.

use the "or". where name like 'jo%' or name like 'jack%'
load the name into a temp table or table variable and join. if you don;t
need wild cards use


where name in (select name from @tbl)


if you do then just use a join

join @tbl on mytable.name like @tbl.name


-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top