如何判断 VARCHAR 变量是否包含子字符串? [英] How can I tell if a VARCHAR variable contains a substring?
本文介绍了如何判断 VARCHAR 变量是否包含子字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我以为是 CONTAINS
,但这对我不起作用.
I thought it was CONTAINS
, but that's not working for me.
我希望这样做:
IF CONTAINS(@stringVar, 'thisstring')
...
我必须运行一个 select
或另一个,这取决于该变量是否包含字符串,而我不知道如何让它工作.我看到的所有示例都使用包含中的列.
I have to run one select
or another, depending on whether that variable contains a string and I can't figure out how to get it to work. All the examples I'm seeing are using columns in the contains.
提前致谢.
推荐答案
标准的SQL方式是使用like:
The standard SQL way is to use like:
where @stringVar like '%thisstring%'
那是在查询语句中.您也可以在 TSQL 中执行此操作:
That is in a query statement. You can also do this in TSQL:
if @stringVar like '%thisstring%'
这篇关于如何判断 VARCHAR 变量是否包含子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文