wood burning stoves*
The moose likes JDBC and the fly likes Multiple output for a case condition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Multiple output for a case condition" Watch "Multiple output for a case condition" New topic
Author

Multiple output for a case condition

Mansi Mishra
Ranch Hand

Joined: Dec 26, 2008
Posts: 50
Hi
I am using PL SQL to write a query

Is it possible to have something like this

Case when (expression)
then (column 1) as column_one , (column 2)as column_two
else (column 3) as column_three
end



http://splashpress.blogspot.com
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8



OCUP UML fundamental and ITIL foundation
youtube channel
Mansi Mishra
Ranch Hand

Joined: Dec 26, 2008
Posts: 50
Jan Cumps wrote:



Thanks Jan
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Mansi Mishra. wrote:
Is it possible to have something like this

Case when (expression)
then (column 1) as column_one , (column 2)as column_two
else (column 3) as column_three
end


Have you tried the above query ? I think we can use it to select conditional column names



[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Mansi Mishra
Ranch Hand

Joined: Dec 26, 2008
Posts: 50
No, the above case query didn't work,
I couldn't find the syntax on the net either...
basically I wanted to fetch two or more columns when one of the case is matched...

Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

are you using sql or pl/sql?
In your initial mail you said pl/sql, but now it seems that you want to use this in an sql query.
You can't write (please correct me if I'm wrong) sql queries with a variable number of columns.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Jan Cumps wrote:
In your initial mail you said pl/sql, but now it seems that you want to use this in an sql query.

Sorry guys, I don't have any knowledge of PL/SQL
Jan Cumps wrote:
You can't write (please correct me if I'm wrong) sql queries with a variable number of columns.

You mean, we can't have this CASE statement in SELECT clause, then let me tell you, I had executed this query on SQL Server 05
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

You mean, we can't have this CASE statement in SELECT clause, then let me tell you, I had executed this query on SQL Server 05
No, that is not what I meant. I was refering to the topmost post.

I do have a question on it though. I know you can use case statement in a sql server query. But I think you can't use case to return two columns namedCOLUMN_ONE and COLUMN_TWO if the expression matches, and only one column named COLUMN_THREE if it does not match. What happens if expression is true for row 1, and false for row 2 in the query?

I was asking the original poster what the root of the problem is.
From the first post, I understood that that person was trying to use conditional logic in pl/sql.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Jan Cumps wrote:
You mean, we can't have this CASE statement in SELECT clause, then let me tell you, I had executed this query on SQL Server 05
No, that is not what I meant. I was refering to the topmost post.
What happens if expression is true for row 1, and false for row 2 in the query?

Oopps , my mistake again, not checking for multiple column, and told you that I can do it

Yes you are right, we can't use CASE condition for multiple columns in THEN condition.
 
Consider Paul's rocket mass heater.
 
subject: Multiple output for a case condition
 
Similar Threads
how to store image in MS SQL Server
JFace 3.3 Problem
help! i can't create CMP to implement 1:1 relationships
problem to connect to SQL server 7
JTable with different objects (or components) in a column