Link to home
Start Free TrialLog in
Avatar of mousemat24
mousemat24

asked on

Change boolean to Int

hi Wonder if you can help me?

I have the following SQL

SELECT id_type, type, max(subtype) from Gtypes group by id_type, nm_type

The problem I have is subtype is a boolean field and the max function dosnt work with booleans, how can I change subtype so that it acts as a integer?

Many thanks
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SELECT id_type, type, max(Cast(subtype as Int)) as MaxSubTpe from Gtypes group by id_type, nm_type
If you have a bit field, it will only support 0,1,null (depending on the nullable state of the field).  I assume based on your question that you could possibly have an id_type, type with a subtype of 1 and/or 0 in which case you if you have one with a 1, you want it, but if not you want the one with a 0?

If you only want with a 1.....
SELECT id_type, type, subtype from Gtypes 
where subType=1
group by id_type, nm_type

Open in new window