若b列的值都为1则返回Y,否则返回X
declare @t table(a int,b int)
insert @t
select 1,1 union all
select 2,1 union all
select 3,1 union all
select 4,0
select b=case when exists(select b from @t where b<>1) then 'X' else 'Y' end
insert @t
select 1,1 union all
select 2,1 union all
select 3,1 union all
select 4,0
select b=case when exists(select b from @t where b<>1) then 'X' else 'Y' end
result: b
-------
X