使用“LIKE”确定变量的内容 [英] Using "LIKE" to determine the contents of a variable

查看:76
本文介绍了使用“LIKE”确定变量的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI


我的问题如下。我有一个表,其中包含ID为ID字段,以ST和#STA开头。我想将ID字段保存在变量中,然后IF以ST开头我想运行存储过程,如果它以#STA开头我想运行不同的存储过程。我怎么做到这一点??



我试着按照以下方式做到这一点:



@id :=ST或#STA



IF @id LIKE#STA

THEN

做什么

结束如果



我有点失落,有人可以帮忙吗?

HI
My problem is as follows. I have a table that has an "ID" field with id''s that begin with "ST" and "#STA". I want to save the ID field in a variable and then "IF" it begins with "ST" i want to run a stored procedure else if it begins with "#STA" i want to run a different stored procedure. How do i accomplish this??

I tried to do it the following way:

@id := "either ST or #STA"

IF @id LIKE "#STA"
THEN
"DO SOMETHING"
END IF

Im a bit lost, can someone help?

推荐答案

使用 LIKE [ ^ ]是您描述的情况您需要使用''%''通配符。

如果字符串应以特定模式开头(在您的情况下为#STA),请将通配符''%'添加到结尾模式。通配符''%''代表任何零个或多个字符的字符串。



所以使用
When using LIKE[^] is the situation you describe you need to use the ''%'' wildcard.
If a string should start with a particular pattern (in your case "#STA") add the wildcard ''%'' to the end of the pattern. The wildcard ''%'' stands for any string of zero or more characters.

So use
IF @id LIKE "#STA%"

并且以#STA开头的任何字符串都意味着DO SOMETHING 已执行。

and any string that begins with "#STA" would mean "DO SOMETHING" is executed.


这篇关于使用“LIKE”确定变量的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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