Solved

Substituting characters in Output

Posted on 2011-03-20
3
311 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
3 Comments
 
LVL 2

Accepted Solution

by:
ramkihardy earned 250 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 250 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Parts and Products table schema in mysql 6 65
Currency in SQL? 2 43
Use Select Query to Return Results as a Form 9 41
Not listening to where 1 14
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

735 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