SQL: Specific LIKE statement

  • Thread starter Thread starter Toni
  • Start date Start date
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?
 
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)
 
Back
Top