How to Use 'Like' with a parameter

后端 未结 3 1618
名媛妹妹
名媛妹妹 2020-12-21 10:56

I want to search for a number embedded in a string in a field in our log table using a parameter.

select * from vwLogs where log_time >\'02/24/2009\' and message lik

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-21 11:28

    You are on the right path, but use it this way:

    SET @ErrorMessage = '%' + @ErrorMessage + '%'
    
    
    SELECT messageId FROM [yourTable]
    WHERE message like @ErrorMessage
    

    Otherwise the server will not be able to cache the execution plan

提交回复
热议问题