473,324 Members | 2,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Query with 1 converted t Yes and 0 converted to No

I have tables where I usually store boolean values as tinyint(1)

I want to do a query that will display 'Yes' in the place of '1' and 'No' in
the place of '0'

How to do that?

Thank you
Mostafa
Jul 19 '05 #1
6 9241
Mostafa wrote:
I want to do a query that will display 'Yes' in the place of '1' and 'No' in
the place of '0'


Assuming you have table called tablename and column named val where 0,1
values are, and assuming you want no when value is 0 and yes, if value
is anything else:

select *,if( val=0,'no','yes' ) as val2 from tablename;
If you want values 0='no', 1='yes', anything else='error', check out
case-when--then-else structures at:

http://www.mysql.com/doc/en/Control_flow_functions.html
Jul 19 '05 #2
Mostafa wrote:
I want to do a query that will display 'Yes' in the place of '1' and 'No' in
the place of '0'


Assuming you have table called tablename and column named val where 0,1
values are, and assuming you want no when value is 0 and yes, if value
is anything else:

select *,if( val=0,'no','yes' ) as val2 from tablename;
If you want values 0='no', 1='yes', anything else='error', check out
case-when--then-else structures at:

http://www.mysql.com/doc/en/Control_flow_functions.html
Jul 19 '05 #3
Mostafa wrote:
I want to do a query that will display 'Yes' in the place of '1' and 'No' in
the place of '0'


Assuming you have table called tablename and column named val where 0,1
values are, and assuming you want no when value is 0 and yes, if value
is anything else:

select *,if( val=0,'no','yes' ) as val2 from tablename;
If you want values 0='no', 1='yes', anything else='error', check out
case-when--then-else structures at:

http://www.mysql.com/doc/en/Control_flow_functions.html
Jul 19 '05 #4
Thank you very much Aggro
"Aggro" <sp**********@yahoo.com> wrote in message
news:MR************@read3.inet.fi...
Mostafa wrote:
I want to do a query that will display 'Yes' in the place of '1' and 'No' in the place of '0'


Assuming you have table called tablename and column named val where 0,1
values are, and assuming you want no when value is 0 and yes, if value
is anything else:

select *,if( val=0,'no','yes' ) as val2 from tablename;
If you want values 0='no', 1='yes', anything else='error', check out
case-when--then-else structures at:

http://www.mysql.com/doc/en/Control_flow_functions.html

Jul 19 '05 #5
Thank you very much Aggro
"Aggro" <sp**********@yahoo.com> wrote in message
news:MR************@read3.inet.fi...
Mostafa wrote:
I want to do a query that will display 'Yes' in the place of '1' and 'No' in the place of '0'


Assuming you have table called tablename and column named val where 0,1
values are, and assuming you want no when value is 0 and yes, if value
is anything else:

select *,if( val=0,'no','yes' ) as val2 from tablename;
If you want values 0='no', 1='yes', anything else='error', check out
case-when--then-else structures at:

http://www.mysql.com/doc/en/Control_flow_functions.html

Jul 19 '05 #6
Thank you very much Aggro
"Aggro" <sp**********@yahoo.com> wrote in message
news:MR************@read3.inet.fi...
Mostafa wrote:
I want to do a query that will display 'Yes' in the place of '1' and 'No' in the place of '0'


Assuming you have table called tablename and column named val where 0,1
values are, and assuming you want no when value is 0 and yes, if value
is anything else:

select *,if( val=0,'no','yes' ) as val2 from tablename;
If you want values 0='no', 1='yes', anything else='error', check out
case-when--then-else structures at:

http://www.mysql.com/doc/en/Control_flow_functions.html

Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robert | last post by:
I am having performance issues on a SQL query in Access. My query is accessing and joining several tables (one very large one). The tables are linked ODBC. The client submits the query to the...
4
by: Philip Yale | last post by:
I'm hoping somebody can explain exactly what's going on here - I can't find it documented anywhere. Go to the Northwind database, and run the following SQL: create index IX_UnitPrice on...
5
by: Anton | last post by:
I have a table of zip codes, some with Canadian zips. I'd like to take a zip code and search for nearby zips. For example: Dim theZip As Integer = textbox1.text ....Parameter.Add(@ziplow,...
4
by: Steve | last post by:
I have a products table where the PK is ProductID. Also have the standard Orders table and OrderDetails table. I created a query that joins the Orders table and OrderDetails table. The query...
15
by: Rolan | last post by:
There must be a way to enhance the performance of a query, or find a plausible workaround, but I seem to be hitting a wall. I have tried a few tweaks, however, there has been no improvement. ...
2
by: Alex Scollay | last post by:
Let's say I have a column whose values are all 2-digit integers, e.g. 82 (though it's actually a varchar field). From now on, the column will be able to have 2-digit as well as 3-digit integers....
10
by: aaronrm | last post by:
I have a real simple cross-tab query that I am trying to sum on as the action but I am getting the "data type mismatch criteria expression" error. About three queries up the food chain from this...
24
by: MU | last post by:
Hello I have some code that sets a dropdownlist control with a parameter from the querystring. However, when the querystring is empty, I get an error. Here is my code: Protected Sub...
3
by: Kunal Desale | last post by:
Hello, I am migrating access queries to SQL Server 2005 Queries. My Access Query Is: SELECT qtrade.intordreftrim AS Expr1, qtrade.extordreftrim AS Expr2, qtrade.intinvreftrim AS Expr3,...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.