Skip to content Skip to sidebar Skip to footer

Returning 1 Or 0 In Specific Sql Query

I have three columns in the table MYTABLE (ID, NUM, NAMES). There is a column NAMES. I need to check on NAMES column to see if the first name is JACK or BRUCE and the corresponding

Solution 1:

This works (SQLFiddle demo):

SELECT id, num,
    CASEWHEN names IN ('JACK', 'BRUCE') AND num=0THEN1ELSE0ENDAS mynames
FROM mytable

Solution 2:

selectcasewhenexists
        (
        select*from    YourTable
        where   name in ('JACK', 'BRUCE')
                and NUM =0
        )
        then1else0endfrom    dual

Live example at SQL Fiddle.

Solution 3:

selectcasewhen NAMES in ('JACK','BRUCE') AND NUM = 0
            then 1else0
       end
from your_table

Post a Comment for "Returning 1 Or 0 In Specific Sql Query"