Обсуждение: How can I simply substatue a value in a query?

Поиск
Список
Период
Сортировка

How can I simply substatue a value in a query?

От
Roy Souther
Дата:
I want to do a simple substatution of a value in a query. For example I have a boolean field that wil return t or f
forTrue and False. I would like it to return Yes or No. I don't want to have a 2x2 table to look up the output. I don't
wantto use stored procedue.<br /><br /> I think there is a better way, somthing very simple but I cannot remember what
itis.<br /><table cellpadding="0" cellspacing="0" width="100%"><tr><td><br /><table cellpadding="0" cellspacing="0"
width="100%"><tr><td><u><ahref="mailto:roy@SiliconTao.com">Roy Souther</a></u><br /><u><a
href="http://www.SiliconTao.com">www.SiliconTao.com</a></u><br/> Let Open Source help your business move beyond.<br
/><br/> For security this message is digitally authenticated by <u><a href="http://www.gnupg.org">GnuPG</a></u>.
</td></tr></table><br/><br /><br /></td></tr></table> 

Re: How can I simply substatue a value in a query?

От
"Sean Davis"
Дата:

 
----- Original Message -----
Sent: Monday, June 27, 2005 1:16 PM
Subject: [SQL] How can I simply substatue a value in a query?

I want to do a simple substatution of a value in a query. For example I have a boolean field that wil return t or f for True and False. I would like it to return Yes or No. I don't want to have a 2x2 table to look up the output. I don't want to use stored procedue.

I think there is a better way, somthing very simple but I cannot remember what it is.
 
 
See CASE:
 
Sean
 

Re: How can I simply substatue a value in a query?

От
"Jim Buttafuoco"
Дата:
try case

for example

select case when bool_column then 'Yes' else 'No end from your_table;



---------- Original Message -----------
From: Roy Souther <roy@SiliconTao.com>
To: pgsql-sql@postgresql.org
Sent: Mon, 27 Jun 2005 11:16:58 -0600
Subject: [SQL] How can I simply substatue a value in a query?

> I want to do a simple substatution of a value in a query. For example I
> have a boolean field that wil return t or f for True and False. I would
> like it to return Yes or No. I don't want to have a 2x2 table to look up
> the output. I don't want to use stored procedue.
> 
> I think there is a better way, somthing very simple but I cannot
> remember what it is.
> 
> Roy Souther
> www.SiliconTao.com
> Let Open Source help your business move beyond.
> 
> For security this message is digitally authenticated by GnuPG.
------- End of Original Message -------


Re: How can I simply substatue a value in a query?

От
"Bryan Encina"
Дата:
-----Original Message-----
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]On Behalf Of Roy Souther
Sent: Monday, June 27, 2005 10:17 AM
To: pgsql-sql@postgresql.org
Subject: [SQL] How can I simply substatue a value in a query?


I want to do a simple substatution of a value in a query. For example I have a boolean field that wil return t or f for
Trueand False. I would like it to return Yes or No. I don't want to have a 2x2 table to look up the output. I don't
wantto use stored procedue. 

I think there is a better way, somthing very simple but I cannot remember what it is.

-------------

I think a CASE statement is what you want.  Check the Conditional Expressions section of the docs at:
http://www.postgresql.org/docs/8.0/interactive/functions-conditional.html
HTH,
Bryan Encina



Re: How can I simply substatue a value in a query?

От
davide
Дата:
Bryan Encina wrote:

>-----Original Message-----
>From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]On Behalf Of Roy Souther
>Sent: Monday, June 27, 2005 10:17 AM
>To: pgsql-sql@postgresql.org
>Subject: [SQL] How can I simply substatue a value in a query?
>
>
>I want to do a simple substatution of a value in a query. For example I have a boolean field that wil return t or f
forTrue and False. I would like it to return Yes or No. I don't want to have a 2x2 table to look up the output. I don't
wantto use stored procedue.
 
>
>I think there is a better way, somthing very simple but I cannot remember what it is.
>
>-------------
>
>I think a CASE statement is what you want.  Check the Conditional Expressions section of the docs at:
>http://www.postgresql.org/docs/8.0/interactive/functions-conditional.html
>HTH,
>Bryan Encina
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster
>
>  
>
select case "field"
when 'T' then 'Yes'
when 'F' then 'No'
else null end
from  ...