Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old August 23rd, 2004, 04:12 AM
gintom gintom is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Essex, UK
Posts: 164 gintom User rank is Private First Class (20 - 50 Reputation Level)gintom User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 17 h 16 m 46 sec
Reputation Power: 5
Help with case/decode statement

can anyone please help me, I am making a sql statement compatible with Oracle 8i and SQL Server.

In the SQL statement I have a CASE and a LEFT JOIN. I am relatively new to Oracle so am having a bit of trouble in tring to convert it.

the following code is below:

Code:
select (case LO_SEQ 
when LLL_PARENT_FKEY_LO_SEQ then LLL_CHILD_FKEY_LO_SEQ 
when LLL_CHILD_FKEY_LO_SEQ then LLL_PARENT_FKEY_LO_SEQ else LO_SEQ end) as LO_SEQ,
LO_ROOM_NUMBER, BG_SITE, LO_DESCRIPTION, LO_SEATING_STD, BK_REF,
BKD_SEQ,BKD_ADATE_START,BKD_ADATE_ENDS,BKD_FKEY_BK_SEQ,BKD_FKEY_LO_SEQ 
from FLOCATE, F_BOOK_DATES,F_BOOK_HEADER,FAREALO,
left join F_LNK_LO_LO = (LLL_PARENT_FKEY_LO_SEQ = LO_SEQ or LLL_CHILD_FKEY_LO_SEQ = LO_SEQ or LLL_PARENT_FKEY_LO_SEQ = 0) 
and BKD_ADATE_START >=to_date('20040824 00:00:00','YYYYMMDD HH24:MI:SS') 
and BKD_ADATE_START < to_date('20040823 00:00:00','YYYYMMDD HH24:MI:SS') 
and LO_SEQ not in (0) 
and LO_SEQ > 0 
and BK_STATUS <> 'CX' 
and BG_SEQ = LO_FKEY_BG_SEQ 
and BKD_FKEY_LO_SEQ = LO_SEQ 
and BK_SEQ = BKD_FKEY_BK_SEQ ORDER BY BG_SITE, LO_SEQ, BKD_ADATE_START, LO_ROOM_NUMBER


As I said I am relatively new to Oracle so any help will be greatly appreciated.

Tom

Reply With Quote
  #2  
Old August 24th, 2004, 10:45 AM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
Your query is big enough and table stucture is not provided that's why it is hard for anyone to reply you back as quickly as much. however what i found in your query that there is some problem in using case...when condition and left join, i dont know either it is working or not, now take a look:

select CASE LO_SEQ
when LLL_PARENT_FKEY_LO_SEQ then LLL_CHILD_FKEY_LO_SEQ
when LLL_CHILD_FKEY_LO_SEQ then LLL_PARENT_FKEY_LO_SEQ else LO_SEQ end END as LO_SEQ,
LO_ROOM_NUMBER, BG_SITE, LO_DESCRIPTION, LO_SEATING_STD, BK_REF,
BKD_SEQ,BKD_ADATE_START,BKD_ADATE_ENDS,BKD_FKEY_BK_SEQ,BKD_FKEY_LO_SEQ
from FLOCATE, F_BOOK_DATES,F_BOOK_HEADER,FAREALO,
LEFT JOIN F_LNK_LO_LO -- i assume it is a table name
ON (LLL_PARENT_FKEY_LO_SEQ = LO_SEQ or LLL_CHILD_FKEY_LO_SEQ = LO_SEQ or LLL_PARENT_FKEY_LO_SEQ = 0)
and BKD_ADATE_START >=to_date('20040824 00:00:00','YYYYMMDD HH24:MI:SS')
and BKD_ADATE_START < to_date('20040823 00:00:00','YYYYMMDD HH24:MI:SS')
and LO_SEQ not in (0)
and LO_SEQ > 0
and BK_STATUS <> 'CX'
and BG_SEQ = LO_FKEY_BG_SEQ
and BKD_FKEY_LO_SEQ = LO_SEQ
and BK_SEQ = BKD_FKEY_BK_SEQ ORDER BY BG_SITE, LO_SEQ, BKD_ADATE_START, LO_ROOM_NUMBER

Modification that i made marked by red color. Query is still not guaranteed to be run successfully.

Reply With Quote
  #3  
Old August 24th, 2004, 10:48 AM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
by mistakenly i add END at the end of case...when exp. please dont add it in your query at line# 3 (marked with red color)
when LLL_CHILD_FKEY_LO_SEQ then LLL_PARENT_FKEY_LO_SEQ else LO_SEQ end END as LO_SEQ,

Reply With Quote
  #4  
Old August 24th, 2004, 12:08 PM
gintom gintom is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Essex, UK
Posts: 164 gintom User rank is Private First Class (20 - 50 Reputation Level)gintom User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 17 h 16 m 46 sec
Reputation Power: 5
Yeah sorry about the code structure and size of it, someone else wrote the code and since then has left, leaving me to deal with it.

But thanks for that shafique, I will give it a try at work tomorrow.

Reply With Quote
  #5  
Old August 25th, 2004, 04:35 AM
gintom gintom is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Essex, UK
Posts: 164 gintom User rank is Private First Class (20 - 50 Reputation Level)gintom User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 17 h 16 m 46 sec
Reputation Power: 5
shafique

afraid to say that doesnt work, it is erroring on the first 'when'.

the error message it is returning is:
ORA-00923: FROM keyword not found where expected

Reply With Quote
  #6  
Old August 25th, 2004, 07:40 AM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
Put the case....when expression within a braket then try to run it. If you also send me the table structure so I could help you better.

select (CASE LO_SEQ
when LLL_PARENT_FKEY_LO_SEQ then LLL_CHILD_FKEY_LO_SEQ
when LLL_CHILD_FKEY_LO_SEQ then LLL_PARENT_FKEY_LO_SEQ else LO_SEQ END) LO_SEQ,

Reply With Quote
  #7  
Old August 26th, 2004, 08:28 AM
gintom gintom is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Essex, UK
Posts: 164 gintom User rank is Private First Class (20 - 50 Reputation Level)gintom User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 17 h 16 m 46 sec
Reputation Power: 5
I have sorted I found that I never needed the left join in the query. So now it works, thanks for your help anyway.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Help with case/decode statement


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway