需要动态地给出模式匹配字符串 [英] need to give pattern Matching string dynamically
本文介绍了需要动态地给出模式匹配字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
Hi All,
SELECT * FROM MyTable WHERE Title like 'PR%'
以上查询将给我一个标题的结果集,标题以''PR'开头。
例如:Price,PRofit,Predict等。
但不是PR硬编码我会在变量中得到它@Title =''PR''我需要根据它来过滤
SELECT * FROM MyTable WHERE标题如@PR%
这是投掷错误。
请你帮我解决这个问题
谢谢&问候,
Mathi。
The above query will give me the result set of records having title starting with ''PR''
example: Price,PRofit,Predict etc.
but instead of PR hard coded I''ll get it in a variable say @Title = ''PR'' based on which I need to filter
SELECT * FROM MyTable WHERE Title like @PR %
This is throwing error.
Could you please help me in this to query
Thanks & Regards,
Mathi.
推荐答案
尝试如下...
Try like below...
SELECT * FROM MyTable WHERE Title like @PR + '%'
DECLARE @sqlQuery nVARCHAR(500)
SET @sqlQuery = 'SELECT * FROM #tempSectionDetails WHERE Title like '''+@Title+ '%' + '''ORDER BY Title'
EXECUTE sp_executesql @sqlQuery
即使这对我有用....
Even this worked for me....
这篇关于需要动态地给出模式匹配字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文