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
mousemat24Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
here we go:
SELECT id_type, type, max(CAST(subtype as INT)) from Gtypes group by id_type, nm_type

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ashish PatelCommented:
SELECT id_type, type, max(Cast(subtype as Int)) as MaxSubTpe from Gtypes group by id_type, nm_type
0
BrandonGalderisiCommented:
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

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.