0

I'm trying to make multiple like in the clause like this code but I need to shorten it because I have to repeat this code for several different conditions to create different tables. I have tried all of the solutions from here but somehow none of this works for me. I have also tried LIKE '[40101,40102,40104]%' and LIKE '[40101-40102-40104]%' but it did not work too. What should I do?

SELECT * 
 from table 
 WHERE column LIKE '40101%' 
    OR column LIKE '40102%' 
    OR column LIKE '40105%'
  • 1
    SQL Server does not use double quotes for strings, so your query is a little confusing. – Gordon Linoff Nov 24 '20 at 03:11
  • The [Official Docs](https://learn.microsoft.com/en-us/sql/t-sql/language-elements/like-transact-sql?view=sql-server-ver15) should always be your first port of call. – Dale K Nov 24 '20 at 03:13

1 Answers1

4

For these patterns you can use:

SELECT * 
FROM table 
WHERE column LIKE '4010[125]%'

SQL Server modestly extends LIKE patterns to include character matching.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786