Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Substituting characters in Output

Posted on 2011-03-20
3
Medium Priority
?
315 Views
Last Modified: 2012-05-11
Hello Folks,

I have the following query i want to run

select cat_id, name, description, price, new from table_name
WHERE price > 0

Now the column "new" contains a bolean record which is either "Y" or "N" what i want to happen is that when the column returns results instead of outputting the "Y" I want the records to show the number "1" & "N" substituted by the number "0"

thanks in advance
0
Comment
Question by:Eaddy Barnes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Accepted Solution

by:
ramkihardy earned 1000 total points
ID: 35178095
Option one....
you can creaye another table name supported table
and store the values
col1 col2
Y     1  
N      0.
and you put join from of two tables to get the desired values by writing query like this

select a.cat_id, a.name, a.description, a.price, b.col2 from table_name a join supportedtable b on a.new = b.col1 WHERE a.price > 0

Option 2...

select cat_id, name, description, price, new from table_name
WHERE price > 0
get the values from the query
and check for every by looping throught the rows and do as
if(new.toUpper() =="Y")
set new as 1;
else
new as 0;
Otherwise use Convert Statements in sql....that might help u i think...........
Regards
Ramki....
0
 
LVL 12

Assisted Solution

by:Amick
Amick earned 1000 total points
ID: 35178108
In MySQL it might look like this:

SELECT cat_id, 
name, 
description, 
price, 
CASE new WHEN 
    'Y' THEN 1 
 ELSE 0 
 END as NewProduct
FROM table_name 
WHERE price > 0

Open in new window

0
 
LVL 11

Author Closing Comment

by:Eaddy Barnes
ID: 35178161
I tried both and both worked , thanks guys..
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

609 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