SQL Stored Procedure LIKE

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

    A different approach is to use CHARINDEX(). However, using a function in a WHERE clause will slow down the performance.

    WHERE CHARINDEX(','+area+',',','+@CommunityDec+',')> 0
    

    If you area field is always 3 letters, you can simplify this.

    WHERE CHARINDEX(area,@CommunityDec)> 0
    

    This is a quick solution, but also a stop gap. A better solution is to change the string lookup approach to build a table with one row per search criteria and using a JOIN or sub query.

提交回复
热议问题