Can I use LIKE with IN?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dcharnigo
    New Member
    • Feb 2007
    • 20

    Can I use LIKE with IN?

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

    Code:
    CREATE PROC dbo.GetOrderList1
    (
    	@OrderList varchar(500)
    )
    AS
    BEGIN
    	SET NOCOUNT ON
    
    	DECLARE @SQL varchar(600)
    
    	SET @SQL = 
    	'SELECT OrderID, CustomerID, EmployeeID, OrderDate
    	FROM dbo.Orders
    	WHERE OrderID IN (' + @OrderList + ')'
    
    	EXEC(@SQL)	
    END
    GO
    where OrderList is something like "100,200,300,40 0".

    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.
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Read this

    Happy Coding!!!


    --- CK

    Comment

    • dcharnigo
      New Member
      • Feb 2007
      • 20

      #3
      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)
      ------------------------------------------------------------------------
      123450000000000 0045345 <--RETURN THIS
      123450000863136 2351351 <--RETURN THIS
      987683428937423 7423942
      656674323421312 3131312
      543210000000000 0023131 <--RETURN THIS
      123450000000763 7621369 <--RETURN THIS
      543210887979677 9697999 <--RETURN THIS
      941027373464553 5355355

      Was there something I missed in the article?

      Thanks,

      Dan

      Comment

      Working...