Home » SQL & PL/SQL » SQL & PL/SQL » case
case [message #635445] Mon, 30 March 2015 09:13 Go to next message
palpali
Messages: 138
Registered: December 2014
Location: India
Senior Member
Hallo all..

I am trying to use the case in my where clause, but having Problem with error number:
ORa:00905-keyword missing

I am trying my following test query:

select item1, item2, item3, item4, in_date
  from table1, table2 
where item1 = table1.item1
and case
      when table2.in_date is null then sysdate
      when table2.in_date is not null then table2.in_date
    end 
;



I want to select if in_date is empty then should give me sysdate, if not then the value in it.
can anyone please help me?
thanking you in advance
regards,
Re: case [message #635446 is a reply to message #635445] Mon, 30 March 2015 09:16 Go to previous messageGo to next message
John Watson
Messages: 9003
Registered: January 2010
Location: Global Village
Senior Member
You need to put your CASE statement inthe column projection list, not in the predicate.
Re: case [message #635447 is a reply to message #635446] Mon, 30 March 2015 09:19 Go to previous messageGo to next message
palpali
Messages: 138
Registered: December 2014
Location: India
Senior Member
Hi, thankx for your prompt reply Smile

you mean like:

...............
...............
and in_date = case
when table2.in_date is null then sysdate
when table2.in_date is not null then table2.in_date
end
...............
...............
Re: case [message #635448 is a reply to message #635447] Mon, 30 March 2015 09:22 Go to previous messageGo to next message
John Watson
Messages: 9003
Registered: January 2010
Location: Global Village
Senior Member
You need to go back to the basics of SQL. Do you know what a "predicate" is? Do you understand the terms "column projection" and "row selection"?
Re: case [message #635452 is a reply to message #635445] Mon, 30 March 2015 10:07 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

Please refer to your previous topic: CASE in WHERE Clause

Re: case [message #635455 is a reply to message #635452] Mon, 30 March 2015 10:31 Go to previous messageGo to next message
cookiemonster
Messages: 13975
Registered: September 2008
Location: Rainy Manchester
Senior Member
I'd use nvl instead of case for this.
Re: case [message #635469 is a reply to message #635455] Mon, 30 March 2015 14:37 Go to previous messageGo to next message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
select item1, item2, item3, item4, NVL(in_date,SYSDATE)
from table1, table2
where TABLE2.item1 = table1.item1;

[Updated on: Mon, 30 March 2015 14:38]

Report message to a moderator

Re: case [message #635489 is a reply to message #635469] Tue, 31 March 2015 01:07 Go to previous message
palpali
Messages: 138
Registered: December 2014
Location: India
Senior Member
Thank you all for your great Suggestion n help Smile
Previous Topic: Split CLOB column to multiple columns within a row
Next Topic: Select query is hitting the database multiple times
Goto Forum:
  


Current Time: Wed Aug 26 05:55:58 CDT 2026