I have a table in SQL Server that contains a column yesno
.
我在SQL Server中有一个包含列yesno的表。
If at least one of the rows has the column yesno=1
then I need to return only one row yes.
如果至少有一行有yesno = 1列,那么我只需返回一行yes。
I made a query that returns for every row if is yes or no.
我做了一个查询,如果是或否则返回每一行。
(select (case when isnull(coalesce(dl.yesno,'2'),'2')='1' then 'Yes' else 'NO' END)
from table dl where dl.ID='A5454322-C239-4FF2-A458-8A9BD79C1839')
3 个解决方案
#1
1
select 'yes'
where exists (select 1 from the_table where yesno = '1');
SQLfiddle example: http://sqlfiddle.com/#!3/069204/1
SQLfiddle示例:http://sqlfiddle.com/#!3/069204/1
#2
0
select 'yes' where exists (select * from MyTable where [yesno]='1')
#3
0
select top 1 'yes' from table where yesno = 1
#1
1
select 'yes'
where exists (select 1 from the_table where yesno = '1');
SQLfiddle example: http://sqlfiddle.com/#!3/069204/1
SQLfiddle示例:http://sqlfiddle.com/#!3/069204/1
#2
0
select 'yes' where exists (select * from MyTable where [yesno]='1')
#3
0
select top 1 'yes' from table where yesno = 1