• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

[Oracle] CASE Syntax in a SELECT

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there
I'm stuck in Oracle by trying to overtake the MS SQLs nice syntax

This query gave a result like:
12345 340'000.00 23'060.00
Depending on the "trn"-value, it summed the amount of the transaction either in column 2 or 3.
When I try now to accomplish this in Oracle-Syntax, I'm charmed by the idea, to use CASE/END aswell.
But when I use it the following way...

I have the Oracle error ORA-00907: missing right parenthesis
I know that I could accomplish it like...

... but don't like doing it this way.
You're idea? Am I too MSSQL fixed? Shall I use the second, working way?
Thanxx in advance!
Pumpel
 
Chris Neff
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've found it...

I forgot to use the () around the CASE/END Syntax. Now I've, depending on the both valid contents of trn ('in' and 'out') two rows with each data. I'll merge them et voil� - done.
Greetings
Pumpelche
 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad you found a solution, and welcome to JavaRanch "Pumpelche".

Your display name doesn't quite fit the famous JavaRanch naming policy. Could you please take a minute to change your display name to show 2 names, preferably your real names. (It's all about maintaining our professional image - don't let the one-eyed moose fool you!).

Thanks and hope you'll be visiting the ranch often,
Pauline
 
Chris Neff
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pauline
Forgive me - here it is..., my real name.
Greetings
Chris
 
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For what it's worth, here's how I would write that in Oracle:

Note that I put the table alias "in" in quotations because "in" is a reserved word in SQL. Otherwise, I believe Oracle's trying to parse the query with in as an operator.
Oddly, I can't reproduce your original parenthesis error. Nor can I get your proposed solution to work. I've used CASE...WHEN inside grouping functions many times, but I'd never seen your approach of using the grouping function as the THEN value.
Anyhow, the CASE...WHEN...THEN...END statement rules.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic