Solved

Substituting characters in Output

Posted on 2011-03-20
3
307 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:greeneel
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:greeneel
ID: 35178161
I tried both and both worked , thanks guys..
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now