How to use LIKE in a t-sql dynamic statement in a stored procedure?

后端 未结 5 583
耶瑟儿~
耶瑟儿~ 2021-01-13 06:47

I\'m trying to use the LIKE keyword with the % wildcards wrapping the parameter, but I\'m not sure how to get the % characters into the statement without breaking it. Right

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-13 07:26

    declare @Cmd nvarchar(2000)
    declare @eName varchar(10)
    set @eName='a'
    set @Cmd= 'select * from customer1 where name LIKE '''+'%' +@eName+ '%' + ''''
    print @Cmd
    EXECUTE sp_executesql @Cmd
    

提交回复
热议问题