How can I simply substatue a value in a query?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

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 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.

[hidden email]
www.SiliconTao.com
Let Open Source help your business move beyond.

For security this message is digitally authenticated by GnuPG.




signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

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
 
Reply | Threaded
Open this post in threaded view
|

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

Jim Buttafuoco
In reply to this post by Roy Souther
try case

for example

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



---------- Original Message -----------
From: Roy Souther <[hidden email]>
To: [hidden email]
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 -------

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to [hidden email])
Reply | Threaded
Open this post in threaded view
|

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

Bryan Encina
In reply to this post by Roy Souther
-----Original Message-----
From: [hidden email] [mailto:[hidden email]]On Behalf Of Roy Souther
Sent: Monday, June 27, 2005 10:17 AM
To: [hidden email]
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.

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

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
Reply | Threaded
Open this post in threaded view
|

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

Davide-24
Bryan Encina wrote:

>-----Original Message-----
>From: [hidden email] [mailto:[hidden email]]On Behalf Of Roy Souther
>Sent: Monday, June 27, 2005 10:17 AM
>To: [hidden email]
>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.
>
>-------------
>
>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  ...



---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match