Quantcast
Channel: is it possible to select EXISTS directly as a bit? - Stack Overflow
Viewing latest article 4
Browse Latest Browse All 10

Answer by JohnLBevan for is it possible to select EXISTS directly as a bit?

$
0
0

I'm a bit late on the uptake for this; just stumbled across the post. However here's a solution which is more efficient & neat than the selected answer, but should give the same functionality:

declare @t table (name nvarchar(16))
declare @b bit

insert @t select N'Simon Byorg' union select N'Roe Bott'


select @b = isnull((select top 1 1 from @t where name = N'Simon Byorg'),0)
select @b whenTrue

select @b = isnull((select top 1 1 from @t where name = N'Anne Droid'),0)
select @b whenFalse

Viewing latest article 4
Browse Latest Browse All 10

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>