If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Chit Chat > Case Statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-03-09, 08:28
abbymagga abbymagga is offline
Registered User
 
Join Date: Aug 2009
Posts: 1
Question Case Statement

I am using Oracle 10g. Sorry about that. I had alias' set up and then deleted them. I am trying to look for the start_time. Looking first at one status_id and if the start_time is null, then looking at another status id for the start_time.

SELECT 'BLUEPRINT' as Type, eng_req_ID AS ADEPT_ID
FROM
(SELECT eng_req_id, MIN (start_time) AS BP_START,
CASE
when status_id = 2013 AND category_id = 20 and start_time is not null
then start_time
When status_id = 3014 and category_id = 20 and start_time is not null
then start_time
else ''
end)
from cscape1.eng_req_cat_status_log@test
GROUP BY eng_req_id)


I am trying to do a basic IF, Then Else statement looking for a date. I can't get the syntax correct. I want to look at one status Id and if it has a start_time then use it, but if not, I want to look at another Status_id. I am pretty new to this and any help would be appreciated.

SELECT 'BLUEPRINT' as Type, bps.eng_req_ID AS ADEPT_ID,
FROM
(SELECT eng_req_id, MIN (start_time) AS BP_START,
CASE
when status_id = 2013
AND category_id = 20
WHEN
status_id = 3014
AND category_id = 17
else ''
end
from cscape1.eng_req_cat_status_log@test
GROUP BY eng_req_id)

Last edited by abbymagga; 08-03-09 at 09:02.
Reply With Quote
  #2 (permalink)  
Old 08-03-09, 08:40
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,516
you have several problems here

first, you say you're looking for a date, but then you say you want to use a status_id

second, your CASE is missing the THEN clauses

finally, your outer query references the non-existent bps table and fails to use the MAX value of the derived table subquery, which is also missing its alias

wanna try again?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 08-03-09, 08:45
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Fourth you have posted in Chitty Chat and not told us your RDBMS. Rudy might recognise it, but I don't.

Please let us know your RDBMS and I'll move the thread to the appropriate forum.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On