sql-server - 是否可以将 Like 与 ALL 关键字一起使用

标签 sql-server tsql stored-procedures

假设我有以下内容,

declare @A table (a int)

insert into @A
select 1 union all
select 2 union all
select 3

select a FROM @A 
where a > ALL (select 1 union all select 2)

这会起作用。但是我需要在这里使用 Like 而不是 greater than,

declare @A table (a int)

insert into @A
select 1 union all
select 2 union all
select 3

select a FROM @A 
where a LIKE ALL (select 1 union all select 2)

请帮帮我。

编辑: 这是我原来的旧表的样子,

declare @A table (a varchar(500))

insert into @A
select 'a;b;c' union all
select 'a;d;b' union all
select 'c;a;e'

我的应用程序在我的 SP 中将值作为“a;b”或“b;c;a”等发送,

现在我只需要选择表@A 中具有 a 和 b 或 b 和 c 和 a 的那些行。 我在我的 SP 中使用拆分功能将用户输入作为表格。 这就是为什么我需要在这里使用 Like ALL。但也欢迎任何其他建议。

最佳答案

无法使用 all与喜欢。如果我理解正确的话,你可以使用类似的东西。

declare @T table (ID int primary key, Col varchar(25))

insert into @T
select 1, 'a;b;c' union all
select 2, 'a;b;c' union all
select 3, 'a;d;b' union all
select 4, 'bb;a;e'

declare @Input table(val varchar(10))
insert into @Input values('a')
insert into @Input values('b')

select T.ID
from @T as T
  inner join @Input as I
    on ';'+T.Col+';' like '%;'+I.val+';%'
group by T.ID    
having count(t.ID) = (select count(*) from @Input)

结果

ID
1
2
3

关于sql-server - 是否可以将 Like 与 ALL 关键字一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6310417/

相关文章:

sql-server - 在 SQL Server 数据库中存储时间间隔的最佳方法是什么

sql-server - 创建具有动态列数的临时表

sql-server - 检查用户是否是 SQL Server 中 dbo 角色的成员

sql - SQL Server 触发器内的存储过程调用是否隐式线程安全且原子?

sql-server - 如何使用密码保护我的 SQL Server 数据库?

tsql - 我是否必须显式创建 #temp 表?

sql - 如何获取格式为 MM/DD/YYYY 的最新日期顺序

mysql - 如何创建存储过程并在预定时间运行它(在 MYSQL 中)

java - 如何在 hibernate 中调用程序?

sql - sql中IF语句的简写