SQL Stored Procedure LIKE

后端 未结 7 1892
野的像风
野的像风 2021-02-20 11:38

This is a simple question and I can\'t seem to think of a solution.

I have this defined in my stored procedure:

@communityDesc varchar(255) = NULL
         


        
7条回答
  •  无人共我
    2021-02-20 12:36

    This article could help you by your problem:

    http://sqlperformance.com/2012/07/t-sql-queries/split-strings

    In this article Aaron Bertrand is writing about your problem. It's really long and very detailed.

    One Way would be this:

    CREATE FUNCTION dbo.SplitStrings_XML
    (
       @List       NVARCHAR(MAX),
       @Delimiter  NVARCHAR(255)
    )
    RETURNS TABLE
    WITH SCHEMABINDING
    AS
       RETURN 
       (  
          SELECT Item = y.i.value('(./text())[1]', 'nvarchar(4000)')
          FROM 
          ( 
            SELECT x = CONVERT(XML, '' 
              + REPLACE(@List, @Delimiter, '') 
              + '').query('.')
          ) AS a CROSS APPLY x.nodes('i') AS y(i)
       );
    GO
    

    With this function you only call:

    WHERE AREA IN (SELECT Item FROM dbo.SplitStrings_XML(@communityDesc, N','))
    

    Hope this could help you.

提交回复
热议问题