Combination of 'LIKE' and 'IN' using t-sql

后端 未结 6 831
無奈伤痛
無奈伤痛 2020-12-13 18:12

How can I do this kind of selection:

SELECT * 
FROM Street 
WHERE StreetName LIKE IN (\'% Main Street\', \'foo %\')

Please don\'t tell me t

6条回答
  •  孤街浪徒
    2020-12-13 18:37

    You don't have a lot of choices here.

    SELECT * FROM Street Where StreetName LIKE '% Main Street' OR StreetName LIKE 'foo %'
    

    If this is part of an existing, more complicated query (which is the impression I'm getting), you could create a table value function that does the checking for you.

    SELECT * FROM Street Where StreetName IN (dbo.FindStreetNameFunction('% Main Street|foo %'))
    

    I'd recommend using the simplest solution (the first). If this is nested inside a larger, more complicated query, post it and we'll take a look.

提交回复
热议问题