Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / May 2007

Tip: Looking for answers? Try searching our database.

SQL Query - modifying return values

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
whitsey - 23 May 2007 07:44 GMT
How can I modify return values?

i.e. I perform a query:

SELECT STATUS
FROM USERS

RESULTS
=======
1
2
1
1
1
2
2
3
4

I want to replace the results to display:

RESULTS
=======
Active
Inactive
Active
Active
Active
Inactive
Inactive
Trial
Demonstration

Is there a way to do this within the SQL statement???
Tonkuma - 23 May 2007 09:24 GMT
Use CASE expression.
Tonkuma - 23 May 2007 09:25 GMT
Use CASE expression.
Tonkuma - 23 May 2007 09:25 GMT
Use CASE expression.
Tonkuma - 23 May 2007 09:26 GMT
Use CASE expression.
swami - 23 May 2007 13:18 GMT
db2 => select case s1 when 0 then 'Active' when 1 then 'InActive' end
"STATUS" f
rom statustable

STATUS
--------
InActive
InActive
InActive
Active
Active
Active
Active
InActive

 8 record(s) selected.
swami - 23 May 2007 13:27 GMT
db2 => select case s1 when 0 then 'Active' when 1 then 'InActive' end
"STATUS" f
rom statustable

STATUS
--------
InActive
InActive
InActive
Active
Active
Active
Active
InActive

 8 record(s) selected.
whitsey - 24 May 2007 07:59 GMT
> db2 => select case s1 when 0 then 'Active' when 1 then 'InActive' end
> "STATUS" f
[quoted text clipped - 12 lines]
>
>   8 record(s) selected.

Thanks swami
Joachim Banzhaf - 23 May 2007 17:40 GMT
Hi whitsey,

if you have a table, that relates the numbers to strings, use this table to
join. If not, you could use a common table expression "result" and join it
like this:

with result( num, str ) as
(
 values (1, "Active"),
        (2, "Inactive"),
        (3, "Trial"),
        (4, "Demo")
)
select result.str
from users, result
where users.status = result.num

Not tested, might need minor adjustments, but you get the idea?

HTH,

Joachim Banzhaf

> How can I modify return values?
>
[quoted text clipped - 30 lines]
>
> Is there a way to do this within the SQL statement???
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.