Quantcast
Channel: is it possible to select EXISTS directly as a bit? - Stack Overflow
Browsing latest articles
Browse All 10 View Live

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

Another solution is to use ISNULL in tandem with SELECT TOP 1 1: SELECT ISNULL((SELECT TOP 1 1 FROM theTable where theColumn like 'theValue%'), 0)

View Article



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

SELECT IIF(EXISTS(SELECT * FROM theTable WHERE theColumn LIKE 'theValue%'), 1, 0)

View Article

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

You can use IIF and CAST SELECT CAST(IIF(EXISTS(SELECT * FROM theTable where theColumn like 'theValue%'), 1, 0) AS BIT)

View Article

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

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:...

View Article

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

You can also do the following: SELECT DISTINCT 1 FROM theTable WHERE theColumn LIKE 'theValue%' If there are no values starting with 'theValue' this will return null (no records) rather than a bit 0...

View Article


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

I believe exists can only be used in a where clause, so you'll have to do a workaround (or a subquery with exists as the where clause). I don't know if that counts as a workaround. What about this:...

View Article

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

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...

View Article

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

SELECT CAST(COUNT(*) AS bit) FROM MyTable WHERE theColumn like 'theValue%' When you cast to bit 0 -> 0 everything else -> 1 And NULL -> NULL of course, but you can't get NULL with COUNT(*)...

View Article


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

No it isn't possible. The bit data type is not a boolean data type. It is an integer data type that can be 0,1, or NULL.

View Article


is it possible to select EXISTS directly as a bit?

I was wondering if it's possible to do something like this (which doesn't work): select cast( (exists(select * from theTable where theColumn like 'theValue%') as bit) Seems like it should be doable,...

View Article
Browsing latest articles
Browse All 10 View Live




Latest Images