• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multiple output for a case condition

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

 
Mansi Mishra
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jan Cumps wrote:




Thanks Jan
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
Mansi Mishra
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic