943,682 Members | Top Members by Rank

Ad:
  • Oracle Discussion Thread
  • Unsolved
  • Views: 4428
  • Oracle RSS
Nov 17th, 2008
0

how do I nest a CASE statement in an INNER JOIN

Expand Post »
Hello,

I am trying to nest some CASE statements into INNER JOINs (one CASE per INNER JOIN).

The current code is:
sql Syntax (Toggle Plain Text)
  1. SELECT
  2. a.zone, a.ifield, a.iwhse, a.idesc, a.iposition
  3. FROM schema.itable a
<---This is where I would like to place the INNER JOIN w/ CASE
sql Syntax (Toggle Plain Text)
  1. LEFT OUTER JOIN
  2. (
  3. SELECT
  4. x.icode, x.ikey, x.idesc, x.icurrent
  5. FROM schema.itablex
  6. ) b
  7. ON a.iwhse = b.icode
  8. AND a.ikey = b.ikey
  9. AND icurrent = 'true'
  10. LEFT OUTER JOIN
  11. etc. . . . .

Anyway, I really don't even know where to begin with the syntax (assuming it can be done). I've tried to do the implied INNER JOIN by leaving the INNER JOIN w/ case in this form:
sql Syntax (Toggle Plain Text)
  1. SELECT iitem, ikey
  2. CASE WHEN iitem IS NULL THEN 'Y'
  3. WHEN iitem = ' ' THEN 'Y'
  4. ELSE 'N"
  5. END
  6. FROM schema.itable
  7.  

And, I've also tried to spell out the INNER JOIN and put the CASE statement into the ON clause like this:
sql Syntax (Toggle Plain Text)
  1. INNER JOIN
  2. (
  3. SELECT iitem, ikey
  4. FROM schemai.table
  5. WHERE icurrent = 'true'
  6. )
  7. ON
  8. CASE WHEN iitem IS NULL THEN 'Y'
  9. WHEN iitem = ' ' THEN 'Y'
  10. ELSE 'N"
  11. END
  12.  
. . . also tried with parens around the CASE statement.

I'm not only new to databases and SQL, but am also new to posting on forums for assistance. So, if there's any other info that would be helpful, please let me know.

Thanks!
Last edited by bohil; Nov 17th, 2008 at 11:44 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bohil is offline Offline
1 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Oracle Forum Timeline: Help! Needed to create Oracle abstract data types and collections using SQL*Plus
Next Thread in Oracle Forum Timeline: Problem with pl/sql report





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC