如何判断VARCHAR变量是否包含子字符串? [英] How can I tell if a VARCHAR variable contains a substring?

查看:72
本文介绍了如何判断VARCHAR变量是否包含子字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以为是内容,但这对我不起作用。

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方法是:像这样使用:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆