怎么'^'或'! '在类似运算符和通配符的SQL服务器中工作(%) [英] How '^' or '! ' works in SQL server with like operator and wild card(%)

查看:79
本文介绍了怎么'^'或'! '在类似运算符和通配符的SQL服务器中工作(%)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



问候!!

今天有人让我解决查询,找到ac栏中任何地方都没有包含A的所有帐号'使用Like opertor而不使用'Not Like'。所以,我认为我们可以使用'^'或'!'来解决查询,但它不起作用。



我试过这个查询

select * from acmast,其中acname如'%[!a]%'



但无法使用'!'解析此查询



所以,我需要知道我错过了什么





最好的问候,

Sukhen Dass



我的尝试:



从acmast中选择*,其中acname如'%[!a]%'

Hi,
Greetings !!
Today someone asked me to solve a query to find all account name which does not contains 'A' anywhere in the column 'acname' using Like opertor and not to use 'Not Like'. So, I thought we can use '^' or '!' to solve the query but it did not work.

I tried this query
select * from acmast where acname like '%[!a]%'

but fail to resolve this query using '!'

So, I need to know what am I missing


Best Regards,
Sukhen Dass

What I have tried:

select * from acmast where acname like '%[!a]%'

推荐答案

如果您阅读LIKE上的文档,我们很容易理解:



LIKE(Transact-SQL)| Microsoft Docs [ ^ ]
It's really easy to figure out if you read the documentation on LIKE:

LIKE (Transact-SQL) | Microsoft Docs[^]


Dave正在制作的是你不使用的!或者^表示SQL中的not,这样你缺少的东西就是理解你试图使用的工具的语法。



有你可以用来避免使用NOT LIKE(或NOT IN)的各种技术就是一个例子:

The point Dave is making is that you do not use ! or ^ to indicate "not" in SQL, so that the thing you are "missing" is understanding the syntax of the tool you are trying to use.

There are various techniques that you can use to avoid using NOT LIKE (or NOT IN) here is one example:
create table demo ([data] varchar(255))
insert into demo ([data]) values
('words without the offending letter'),
('sentence that contains the letter a')

select *
from demo
where patindex('%a%', [data]) = 0

这会返回

words without the offending letter



文档 PATINDEX(Transact-SQL)| Microsoft Docs [ ^ ]



备选方案可以通过 Google [ ^ ]


这篇关于怎么'^'或'! '在类似运算符和通配符的SQL服务器中工作(%)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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