假设我有以下内容,
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/