SQL Stored Procedure LIKE

后端 未结 7 1933
野的像风
野的像风 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:35

    You can simply split this csv using XML and use this to filter in your query. No need to use a User defined function or @Table_Valiable or #Temp_Table here.

    DECLARE @xml as xml,@communityDesc varchar(255) = 'aaa,bbb,ccc'
    
    SET @xml = cast((''+replace(@communityDesc,',' ,'')+'') as xml)
    
    SELECT * FROM TABLE1
    WHERE AREA IN (
        SELECT N.value('.', 'varchar(10)') as value FROM @xml.nodes('X') as T(N)
    ) 
    

    If you required this split values in further process, then you can Insert this to a #table_Variable or #Temp_Table and use them.

提交回复
热议问题