Thread: Retrieving 'Credit' when 'C'

Retrieving 'Credit' when 'C'

From
"Ezequias Rodrigues da Rocha"
Date:
Hello,<br /><br />Does anyone know how to make a Select that even having a Char(1) with the letter C the statement
makesthe rows appearing 'CREDIT' ?<br /><br />Like: <br /> On table:<br /><br />When         Type<br />2007-01-01    C
<br/>2007-01-02    C<br />2007-01-03    C<br /><br />On SQL result<br />When         Type<br /> 2007-01-01    CREDIT<br
/>2007-01-02    CREDIT<br /> 2007-01-03    CREDIT<br /><br />Thanks in advande,<br /><br clear="all" /><br />-- <br />
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=<br/>                                  Atenciosamente
(Sincerely)<br/>                        Ezequias Rodrigues da Rocha<br />
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-<br />A pior das democracias ainda é melhor do
quea melhor das ditaduras<br />The worst of democracies is still better than the better of dictatorships<br /><a
href="http://ezequiasrocha.blogspot.com/">http://ezequiasrocha.blogspot.com/</a> 

Re: Retrieving 'Credit' when 'C'

From
"Rodrigo De León"
Date:
SELECT CASE        WHEN TYPE = 'C'          THEN 'CREDIT'      END AS TYPE FROM mytable


Re: Retrieving 'Credit' when 'C'

From
Alvaro Herrera
Date:
Ezequias Rodrigues da Rocha escribió:
> Hello,
> 
> Does anyone know how to make a Select that even having a Char(1) with the
> letter C the statement makes the rows appearing 'CREDIT' ?

case when column = 'C' then 'CREDIT' end

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


Re: Retrieving 'Credit' when 'C'

From
"Ezequias Rodrigues da Rocha"
Date:
Just a question, where to put it ? I didn't notice yet.

Ezequias

2007/2/15, Alvaro Herrera < alvherre@commandprompt.com>:
Ezequias Rodrigues da Rocha escribió:
> Hello,
>
> Does anyone know how to make a Select that even having a Char(1) with the
> letter C the statement makes the rows appearing 'CREDIT' ?

case when column = 'C' then 'CREDIT' end

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.



--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                                  Atenciosamente (Sincerely)
                        Ezequias Rodrigues da Rocha
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
A pior das democracias ainda é melhor do que a melhor das ditaduras
The worst of democracies is still better than the better of dictatorships
http://ezequiasrocha.blogspot.com/

Re: Retrieving 'Credit' when 'C'

From
"Phillip Smith"
Date:
<div class="Section1"><p class="MsoNormal" style="text-autospace:none"><font face="Courier New" size="2"><span
style="font-size:10.0pt;font-family:"CourierNew"">SELECT      when,</span></font><p class="MsoNormal"
style="margin-left:36.0pt;text-indent:36.0pt;text-autospace:
none"><font face="Courier New" size="2"><span style="font-size:10.0pt;font-family:
"Courier New"">CASE WHEN type = 'C' THEN 'Credit' END AS type</span></font><p class="MsoNormal"
style="text-autospace:none"><fontface="Courier New" size="2"><span style="font-size:10.0pt;font-family:"Courier
New"">FROM       mytable;</span></font><p class="MsoNormal"><font color="navy" face="Arial" size="2"><span
style="font-size:
10.0pt;font-family:Arial;color:navy"> </span></font><p class="MsoNormal"><font color="navy" face="Arial" size="2"><span
style="font-size:
10.0pt;font-family:Arial;color:navy">Assuming your column names are actually “when” and “type” you should just have to
change“mytable” to the correct table name and run in psql or the SQL Window of pgAdmin or wherever you usually run your
SQLqueries to get what you want.</span></font><p class="MsoNormal"><font color="navy" face="Arial" size="2"><span
style="font-size:
10.0pt;font-family:Arial;color:navy"> </span></font><p class="MsoNormal"><font color="navy" face="Arial" size="2"><span
style="font-size:
10.0pt;font-family:Arial;color:navy"> </span></font><p class="MsoNormal" style="margin-left:36.0pt"><font face="Tahoma"
size="2"><spanlang="EN-US" style="font-size:10.0pt;font-family:Tahoma">-----Original Message-----<br /><b><span
style="font-weight:bold">From:</span></b>pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]
<b><spanstyle="font-weight:bold">On Behalf Of </span></b>Ezequias Rodrigues da Rocha<br /><b><span
style="font-weight:bold">Sent:</span></b></span></font><font face="Tahoma" size="2"><span lang="EN-US"
style="font-size:10.0pt;font-family:Tahoma">Friday,16 February 2007</span></font><font face="Tahoma" size="2"><span
lang="EN-US"style="font-size:10.0pt;font-family:Tahoma"> </span></font><font face="Tahoma" size="2"><span lang="EN-US"
style="font-size:10.0pt;font-family:Tahoma">03:45</span></font><fontface="Tahoma" size="2"><span lang="EN-US"
style="font-size:10.0pt;font-family:Tahoma"><br/><b><span style="font-weight:bold">To:</span></b> Ezequias Rodrigues da
Rocha;pgsql-sql@postgresql.org<br /><b><span style="font-weight:bold">Subject:</span></b> Re: [SQL] Retrieving 'Credit'
when'C'</span></font><p class="MsoNormal" style="margin-left:36.0pt"><font face="Times New Roman" size="3"><span
style="font-size:12.0pt"> </span></font><pclass="MsoNormal" style="margin-left:36.0pt"><font face="Times New Roman"
size="3"><spanstyle="font-size:12.0pt">Just a question, where to put it ? I didn't notice yet. </span></font></div><br
/><p><b>*******************Confidentialityand Privilege Notice*******************</b><p> The material contained in this
messageis privileged and confidential to the addressee. If you are not the addressee indicated in this message or
responsiblefor delivery of the message to such person, you may not copy or deliver this message to anyone, and you
shoulddestroy it and kindly notify the sender by reply email. <p> Information in this message that does not relate to
theofficial business of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta. Weatherbeeta, its
employees,contractors or associates shall not be liable for direct, indirect or consequential loss arising from
transmissionof this message or any attachments <br /> 

Re: Retrieving 'Credit' when 'C'

From
"Ezequias Rodrigues da Rocha"
Date:
Perfect,

I learn this lesson now. This case is quite good.

My Best Regards
Ezequias

2007/2/15, Phillip Smith < phillip.smith@weatherbeeta.com.au>:

SELECT      when,

CASE WHEN type = 'C' THEN 'Credit' END AS type

FROM        mytable;

 

Assuming your column names are actually "when" and "type" you should just have to change "mytable" to the correct table name and run in psql or the SQL Window of pgAdmin or wherever you usually run your SQL queries to get what you want.

 

 

-----Original Message-----
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Ezequias Rodrigues da Rocha
Sent:
Friday, 16 February 2007 03:45
To: Ezequias Rodrigues da Rocha; pgsql-sql@postgresql.org
Subject: Re: [SQL] Retrieving 'Credit' when 'C'

 

Just a question, where to put it ? I didn't notice yet.


*******************Confidentiality and Privilege Notice*******************

The material contained in this message is privileged and confidential to the addressee. If you are not the addressee indicated in this message or responsible for delivery of the message to such person, you may not copy or deliver this message to anyone, and you should destroy it and kindly notify the sender by reply email.

Information in this message that does not relate to the official business of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta. Weatherbeeta, its employees, contractors or associates shall not be liable for direct, indirect or consequential loss arising from transmission of this message or any attachments




--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                                  Atenciosamente (Sincerely)
                        Ezequias Rodrigues da Rocha
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
A pior das democracias ainda é melhor do que a melhor das ditaduras
The worst of democracies is still better than the better of dictatorships
http://ezequiasrocha.blogspot.com/