Solved

Substituting characters in Output

Posted on 2011-03-20
3
309 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create a Select Query and Populate a Table 3 48
updating the date data 12 30
MySQL  on Tomcat 8 45
paypal ipn to mysql 3 35
Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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