473,320 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Can I use LIKE with IN?

dcharnigo
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
  7.     SET NOCOUNT ON
  8.  
  9.     DECLARE @SQL varchar(600)
  10.  
  11.     SET @SQL = 
  12.     'SELECT OrderID, CustomerID, EmployeeID, OrderDate
  13.     FROM dbo.Orders
  14.     WHERE OrderID IN (' + @OrderList + ')'
  15.  
  16.     EXEC(@SQL)    
  17. END
  18. GO
  19.  
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?

Thanks.
Aug 5 '09 #1
2 2884
ck9663
2,878 Expert 2GB
Read this

Happy Coding!!!


--- CK
Aug 7 '09 #2
CK--

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
9876834289374237423942
6566743234213123131312
5432100000000000023131 <--RETURN THIS
1234500000007637621369 <--RETURN THIS
5432108879796779697999 <--RETURN THIS
9410273734645535355355

Was there something I missed in the article?

Thanks,

Dan
Aug 7 '09 #3

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

Similar topics

0
by: Madhusudan Singh | last post by:
Hi After months of waiting for Redhat to come out with up to date rpms, I decided to compile a working OpenSSL/ MySQL / PHP / httpd installation for myself. Installed the latest versions of...
0
by: Alexander Skwar | last post by:
Hello! I'm having problems getting PHP 4.3.3RC4 successfully to install on my HP-UX 11.00 server. After a (successfull?) compile, "make install" errors out with this error message: ...
7
by: Darren Gamble | last post by:
Good day, I've sent a message on this to the php-general list already, but unfortunately no one replied. Sorry for the repost. to those that read both... I'm having a problem working with an...
7
by: kecebong | last post by:
I tried to compile php 4.3.3 with gd but it doesn't work, it wasnt show in phpinfo(). My system is redhat 9 and apache 2.0.47 webserver.
0
by: Slavik | last post by:
All libraries were installed (precompiled) This is FreeBSD 5.1 installed zlib, installed jpeg and png libraries (in default directories) GD 2.0.11 source is in /usr/gd-2.0.11 (compiled and...
3
by: Garrett Albright | last post by:
Trying to compile PHP 5 beta 4, and not having much fun... % ./configure --with-apxs --with-mod_charset --with-zlib --with-bz2 --with-curl --with-gd --with-mhash --with-pspell...
0
by: LRW | last post by:
(Not even sure if that's the right way to word the question.) We're trying to migrate to a new server, and upgrade the PHP on the new server in the process. We're using a RedHat Enterprise Server...
9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
3
by: Ron King | last post by:
When I installed Mandrake 10.0 I thought I had Apache, PHP, and MySQL installed correctly. I could serve web pages, MySQL worked, and when I tried the phpinfo() function, I got a page that looked...
13
by: Gary Quiring | last post by:
I need to create an XML string using PHP5. The examples I have followed seem to be using out dated libary calls. I tried new_xmldoc() and new DomDocument. Both get undefined errors. How do I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.