Home » SQL & PL/SQL » SQL & PL/SQL » equal , not equal , nul in same query
equal , not equal , nul in same query [message #318649] Wed, 07 May 2008 08:02 Go to next message
sispk6
Messages: 164
Registered: November 2006
Location: pakistan
Senior Member
if want my requirement to meet in single query as
:-
     deptno = :p , (single record for :p=20)
     deptno != :p , (all record other than :p=20)
     deptno is null  (alll records)
  

and i want to write a query like

 select deptno from dept where deptno =
       decode (deptno ,
                null , deptno ,
                (deptno != :p ) , !:P ,
                 :p ) ;


please help
Re: equal , not equal , nul in same query [message #318650 is a reply to message #318649] Wed, 07 May 2008 08:10 Go to previous messageGo to next message
Michel Cadot
Messages: 64152
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Explain in WORDS what do you want.
Your pseudo code is meaningless.
What is the input?

Regards
Michel
Re: equal , not equal , nul in same query [message #318701 is a reply to message #318650] Wed, 07 May 2008 11:28 Go to previous messageGo to next message
sispk6
Messages: 164
Registered: November 2006
Location: pakistan
Senior Member
ya i have three radio buttons in my form ,


1. dept50.
2. all depts.
3. all except dept50.

i retrieve data from query .

i dont have column in table for radiobuton valus ,
i dont want to use if-else approach ,
please help
Re: equal , not equal , nul in same query [message #318704 is a reply to message #318701] Wed, 07 May 2008 11:48 Go to previous messageGo to next message
Michel Cadot
Messages: 64152
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
You only have 3 values, use 3 queries.

Regards
Michel
Re: equal , not equal , nul in same query [message #318721 is a reply to message #318649] Wed, 07 May 2008 14:07 Go to previous messageGo to next message
Bill B
Messages: 1484
Registered: December 2004
Senior Member
select deptno from dept
where (button = '1' and deptno = '50')
or (button = '2')
or (button = '3' AND DEPTNO <> '50');
Re: equal , not equal , nul in same query [message #318740 is a reply to message #318721] Wed, 07 May 2008 16:30 Go to previous messageGo to next message
Littlefoot
Messages: 20901
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
As it is a Forms question, you could (depending on a selected radio button) set the DEFAULT_WHERE block property (using the SET_BLOCK_PROPERTY built-in) and simply execute query in order to fetch desired records.
Re: equal , not equal , nul in same query [message #318771 is a reply to message #318649] Wed, 07 May 2008 23:00 Go to previous messageGo to next message
alister
Messages: 101
Registered: August 2007
Location: India
Senior Member
If you want a single query try this

select deptno p_rec,null ex_p,null all_rec from deptno where deptno=:p
union
select null p_rec,deptno ex_p,null all_rec from deptno where deptno!=:p
union
select null p_rec,null ex_p,deptno all_rec from deptno where deptno is null


I hope I have understood you correctly

Regards

Alister
Re: equal , not equal , nul in same query [message #318796 is a reply to message #318771] Thu, 08 May 2008 00:39 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
This is the same as "select distinct * from deptno"
Re: equal , not equal , nul in same query [message #318997 is a reply to message #318649] Thu, 08 May 2008 11:53 Go to previous message
sispk6
Messages: 164
Registered: November 2006
Location: pakistan
Senior Member
thanx a lot -> Bill B.
your solutions rocks
Previous Topic: How to Convert Db2 procedures to Sql procedures
Next Topic: SQL PLUS query result in Horizantal way
Goto Forum:
  


Current Time: Sat Dec 10 16:52:52 CST 2016

Total time taken to generate the page: 0.08315 seconds