私はこれが非常に遅いことを知っていますが、同様の状況にありました。多くのパラメーターを受け入れ、それらのパラメーターを使用して複数のRDBMSシステムからのデータを集約する一連のストアドプロシージャに「Like In」演算子が必要だったため、RDBMS固有のトリックは機能しませんが、ストアドプロシージャと関数はMS SQL Serverで実行されるため、RDBMSごとに完全なSQLステートメントを生成する機能にT-SQLを使用できますが、出力はRDBMSからかなり独立している必要があります。
これが、区切り文字列(ストアドプロシージャに渡されるパラメーターなど)をSQLのブロックに変換するために今のところ私が思いついたものです。「LIKE IN」を「地衣」と呼んでいます。それを得る?
Lichen.sql
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =======================================================================
-- Lichen - Scalar Valued Function
-- Returns nvarchar(512) of "LIKE IN" results.  See further documentation.
-- CREATOR: Norman David Cooke
-- CREATED: 2020-02-05
-- UPDATED:
-- =======================================================================
CREATE OR ALTER FUNCTION Lichen 
(
    -- Add the parameters for the function here
    @leadingAnd bit = 1,
    @delimiter nchar(1) = ';',
    @colIdentifier nvarchar(64),
    @argString nvarchar(256)
)
RETURNS nvarchar(512)
AS
BEGIN
    -- Declare the return variable here
    DECLARE @result nvarchar(512)
    -- set delimiter to detect (add more here to detect a delimiter if one isn't provided)
    DECLARE @delimit nchar(1) = ';'
    IF NOT @delimiter = @delimit 
        SET @delimit = @delimiter
    -- check to see if we have any delimiters in the input pattern
    IF CHARINDEX(@delimit, @argString) > 1  -- check for the like in delimiter
    BEGIN  -- begin 'like in' branch having found a delimiter
        -- set up a table variable and string_split the provided pattern into it.
        DECLARE @lichenTable TABLE ([id] [int] IDENTITY(1,1) NOT NULL, line NVARCHAR(32))
        INSERT INTO @lichenTable SELECT * FROM STRING_SPLIT(@argString, ';')
        -- setup loop iterators and determine how many rows were inserted into lichen table
        DECLARE @loopCount int = 1
        DECLARE @lineCount int 
        SELECT @lineCount = COUNT(*) from @lichenTable
        -- select the temp table (to see whats inside for debug)
        --select * from @lichenTable
        -- BEGIN AND wrapper block for 'LIKE IN' if bit is set
        IF @leadingAnd = 1
            SET @result = ' AND ('
        ELSE
            SET @result = ' ('
        -- loop through temp table to build multiple "LIKE 'x' OR" blocks inside the outer AND wrapper block
        WHILE ((@loopCount IS NOT NULL) AND (@loopCount <= @lineCount))
        BEGIN -- begin loop through @lichenTable
            IF (@loopcount = 1) -- the first loop does not get the OR in front
                SELECT @result = CONCAT(@result, ' ', @colIdentifier, ' LIKE ''', line, '''') FROM @lichenTable WHERE id = @loopCount
            ELSE  -- but all subsequent loops do
                SELECT @result = CONCAT(@result, ' OR ', @colIdentifier, ' LIKE ''', line, '''') FROM @lichenTable WHERE id = @loopCount
            SET @loopcount = @loopCount + 1     -- increment loop
        END -- end loop through @lichenTable
        -- set final parens after lichenTable loop
        SET @result = CONCAT(@result, ' )')
    END  -- end 'like in' branch having found a delimiter
    ELSE -- no delimiter was provided
    BEGIN   -- begin "no delimiter found" branch
        IF @leadingAnd = 1 
            SET @result = CONCAT(' AND ', @colIdentifier, ' LIKE ''' + @argString + '''')
        ELSE
            SET @result = CONCAT(' ', @colIdentifier, ' LIKE ''' + @argString + '''')
    END     -- end "no delimiter found" branch
    -- Return the result of the function
    RETURN @result
END  -- end lichen function
GO
区切り文字の検出が計画されている可能性がありますが、現時点ではデフォルトでセミコロンに設定されているのでdefault、そこに入力するだけで済みます。これにはおそらくバグがあります。の@leadingAndパラメータは、それが他のWHERE句の追加とうまくに収まるように、あなたはブロックの前に先頭の「AND」プットをしたいかどうかを判断するだけのビットの値です。
使用例(argStringに区切り文字あり)
SELECT [dbo].[Lichen] (
   default        -- @leadingAND, bit, default: 1
  ,default        -- @delimiter, nchar(1), default: ';'
  ,'foo.bar'      -- @colIdentifier, nvarchar(64), this is the column identifier
  ,'01%;02%;%03%' -- @argString, nvarchar(256), this is the input string to parse "LIKE IN" from
)
GO
以下を含むnvarchar(512)を返します:
 AND ( foo.bar LIKE '01%' OR foo.bar LIKE '02%' OR foo.bar LIKE '%03%' ) 
入力に区切り文字が含まれていない場合も、ブロックをスキップします。
使用例(argStringに区切り文字なし)
SELECT [dbo].[Lichen] (
   default        -- @leadingAND, bit, default: 1
  ,default        -- @delimiter, nchar(1), default: ';'
  ,'foo.bar'      -- @colIdentifier, nvarchar(64), this is the column identifier
  ,'01%'          -- @argString, nvarchar(256), this is the input string to parse "LIKE IN" from
)
GO
以下を含むnvarchar(512)を返します:
 AND foo.bar LIKE '01%'
私はこれについて作業を続けるつもりですので、私が何かを見過ごしていた場合は(目立って明白かどうかにかかわらず)、コメントまたはお気軽にご連絡ください。