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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Wildard in an "IN" statement?

Author  Topic 

kelemvor
Starting Member

6 Posts

Posted - 2011-06-24 : 16:23:47
I know I could do this with a big OR statement with LIKE commands but I'm not sure if there's an easier way. This is for Oracle SQL if that matters.

I basically want to select things where the value is IN a list of values.

e.g. Where XXX In ('a1234','b1234','c1234')

But I also need to have certain things that are open ended. Such as the three items above or anything that starts with a D or E.

So what I was going to use was:
Where XXX In ('a1234','b1234','c1234','d%','e%')

But that didn't work.

Can I use a wildcard in an IN statement like that or am I better off using multiple LIKEs with or statements.

Thanks.

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-06-25 : 10:34:55
With the caveat that everything I am going to say is based on my familiarity with Microsoft SQL:

1. You cannot use the wild-card operators like you are trying to do in the "IN" clause. As you correctly guessed, you would need to use like operator with multiple OR conditions. When you use OR conditions, be sure to use appropriate brackets to take care of operator precedence.

2. If you have more than a handful of these conditions, it may be more efficient to insert all those strings into a (temp) table and then join to that table. The join conditions can use "LIKE" keyword.

3. You would get much faster and better responses to Oracle questions on a forum such as dbforums.com. While there may be some people on this forum who are familiar with Oracle, the forum itself is for Microsoft SQL Server, so Oracle experts are likely to be far and few in between on this forum.
Go to Top of Page
   

- Advertisement -