Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sross81
Posting Yak Master
228 Posts |
Posted - 2009-03-23 : 16:49:35
|
| Is it possible to put a Like statement in an In statement? I don't want to hard code like this but they are leaving me no choice.select * from fdb_medicationwhere brand_name IN(like('%hand held shower%','raised toilet seat','chucks','blood pressure monitor','glucometer','lancets','test strips'))Thanks in Advance!Sherri |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2009-03-23 : 17:12:09
|
If there's logic to this, you can always build a query dynamicly as well and use EXEC(...) Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881 |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
sross81
Posting Yak Master
228 Posts |
Posted - 2009-03-23 : 18:23:54
|
Thanks for your help. I have decided that they are crazy and I am not hard coding this thing its like 36000 names!quote: Originally posted by sross81 Is it possible to put a Like statement in an In statement? I don't want to hard code like this but they are leaving me no choice.select * from fdb_medicationwhere brand_name IN(like('%hand held shower%','raised toilet seat','chucks','blood pressure monitor','glucometer','lancets','test strips'))Thanks in Advance!Sherri
Thanks in Advance!Sherri |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2009-03-23 : 21:15:37
|
You can put the brand names that you want to check against in a table and then join on the table. It would SOMETHING LIKE this:declare @table table (searchTerm varchar(32));insert into @table (searchTerm) values ('hand held shower');insert into @table (searchTerm) values ('raised toilet seat');select *from fb_medication f inner join @table t on f.brand_name like '%' + t.searchTerm + '%'You may want to use a table or temp table instead of a table variable.If you want to search for exact phrases in some and partial matches in other, include the wild card qualifer (%) in @table.Also, depending on whether you care about duplicate rows or not, you might want to use select distinct. |
 |
|
|
|
|
|
|
|