Quantcast
Channel: is it possible to select EXISTS directly as a bit? - Stack Overflow
Viewing all articles
Browse latest Browse all 10

Answer by Alex K. for is it possible to select EXISTS directly as a bit?

$
0
0

No, you'll have to use a workaround.

If you must return a conditional bit 0/1 another way is to:

SELECT CAST(
   CASE WHEN EXISTS(SELECT * FROM theTable where theColumn like 'theValue%') THEN 1 
   ELSE 0 
   END 
AS BIT)

Or without the cast:

SELECT
   CASE
       WHEN EXISTS( SELECT 1 FROM theTable WHERE theColumn LIKE 'theValue%' )
            THEN 1 
       ELSE 0 
   END

Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles



Latest Images

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