Is there a combination of “LIKE” and “IN” in SQL?

后端 未结 25 1669
灰色年华
灰色年华 2020-11-22 03:08

In SQL I (sadly) often have to use \"LIKE\" conditions due to databases that violate nearly every rule of normalization. I can\'t change that right now. But tha

25条回答
  •  太阳男子
    2020-11-22 03:56

    Starting with 2016, SQL Server includes a STRING_SPLIT function. I'm using SQL Server v17.4 and I got this to work for me:

    DECLARE @dashboard nvarchar(50)
    SET @dashboard = 'P1%,P7%'
    
    SELECT * from Project p
    JOIN STRING_SPLIT(@dashboard, ',') AS sp ON p.ProjectNumber LIKE sp.value
    

提交回复
热议问题