By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,659 Members | 1,611 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,659 IT Pros & Developers. It's quick & easy.

Can I use LIKE with IN?

P: 20
I found this example of passing a list into a stored procedure:

Expand|Select|Wrap|Line Numbers
  1. CREATE PROC dbo.GetOrderList1
  2. (
  3.     @OrderList varchar(500)
  4. )
  5. AS
  6. BEGIN
  9.     DECLARE @SQL varchar(600)
  11.     SET @SQL = 
  12.     'SELECT OrderID, CustomerID, EmployeeID, OrderDate
  13.     FROM dbo.Orders
  14.     WHERE OrderID IN (' + @OrderList + ')'
  16.     EXEC(@SQL)    
  17. END
  18. GO
where OrderList is something like "100,200,300,400".

What I want to do is find OrderID's that begin with any of the items in the list, so WHERE OrderID LIKE '100%' OR LIKE '200%' etc [WHERE OrderID LIKE IN...]. Is something like this possible?

Aug 5 '09 #1
Share this Question
Share on Google+
2 Replies

Expert 2.5K+
P: 2,878
Read this

Happy Coding!!!

--- CK
Aug 7 '09 #2

P: 20

I read over the article, it seems like it was more about using REGEX and WILDCARDS. What I was trying to avoid was splitting the string apart and building a dynamic query. Like I said before I am going to pass in an array of about 6 numbers that the column might start with. The value is 28 digits long, I am going to pass in the first 4 or 5 digits, I want to pull all the records that match the set of the first 4 or 5 digits. Example:

Using the code below data will be (I want the columns <--):

@OrderList = (12345,54321)

CIF--------------------------------- OTHER COLUMN(S)
1234500000000000045345 <--RETURN THIS
1234500008631362351351 <--RETURN THIS
5432100000000000023131 <--RETURN THIS
1234500000007637621369 <--RETURN THIS
5432108879796779697999 <--RETURN THIS

Was there something I missed in the article?


Aug 7 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.