简体   繁体   English

SQL Server选择看起来像'喜欢'

[英]SQL Server select looks like 'Like'

I have question about SQL Server's LIKE operator. 我对SQL Server的LIKE运算符有疑问。

I have a table Table1 : 我有一张桌子Table1

app    ex  
----------
test   210

I am writing some select from program select is looks like this: 我正在编写一些select from program select,如下所示:

select app 
from Table1 
where ex Like = '210203'

I have tried to use ( %,%.%,[] ). 我试过用( %,%.%,[] )。

If I try [] this one like this [210]203 it is working but there will be more data so if there will be 2102 in ex I want this to choose this one. 如果我尝试[]这样的[210] 203它正在工作,但会有更多的数据,所以如果前面有2102我想要这个选择这个。

But it isn't selecting nothing beacouse ver is 210203 and in ex is 210 但它并没有选择任何beacouse ver是210203而ex是210

How can I manage this that I selected 210 the variable can't be changed there will be always variable bigger than 'ex' data 我如何管理我选择的210变量无法更改,总是变量大于'ex'数据

Please help me anyone. 请帮助我。

You query is not right, you don't use "=" operator in Like. 你查询不对,你不要在Like中使用“=”运算符。

SELECT app FROM Table1 WHERE ex LIKE '%210%'

In this case will filter values who have 210 inside. 在这种情况下,将过滤内部210的值。

If you use for ex: Like ='%210' will filter values who ends with 210.. and so on. 如果您使用ex: Like ='%210'将过滤以210 ...结尾的值。依此类推。

Update 更新

You can use this too, i think will help you 您也可以使用它,我想会帮助您

declare @Value varchar(50)
set @value = '123AAAAA123'

select * from Table where @Value like '%' + column + '%'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM