?
Solved

Change boolean to Int

Posted on 2008-02-08
3
Medium Priority
?
1,650 Views
Last Modified: 2008-02-08
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
0
Comment
Question by:mousemat24
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 20849477
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
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20849498
SELECT id_type, type, max(Cast(subtype as Int)) as MaxSubTpe from Gtypes group by id_type, nm_type
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 20849749
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to shrink a transaction log file down to a reasonable size.

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question