We help IT Professionals succeed at work.

SQL Boolean formula in select

jglazer63
jglazer63 used Ask the Experts™
on
I need the syntax for:

select (a > b) as test

Basically I need to test if value a is greater than value b in a select statement and return the boolean response.  The above won't work.

I'm sure this is easy but I'm missing something.  I need all the rows, not just if a>b (where) but actually a true or false.

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
The following statement would work for you;

SELECT CASE WHEN a > b THEN 'TRUE' ELSE 'FALSE' END
Anuradha GoliSystems Development / Support Specialist

Commented:
SELECT	* ,
CASE	WHEN	A > B  
THEN	'TRUE'
ELSE	'FALSE' 
END	AS	BOOLVAL 
FROM	TABLE1

Open in new window

output is:output

Author

Commented:
Worked perfect!