×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

need help with query retuning only records where value > 0

need help with query retuning only records where value > 0

need help with query retuning only records where value > 0

(OP)
Hello,

I am writing a query and part of my select state is this: SUM (A.INVOICE_AMOUNT) - B.INVOICE_AMOUNT) as MINE

now this works well but returns all values and I am only after values greater than 0. i am familiar with MSSQL but very rusty with oracle syntax. I tried using a case statement and I tried to add in the where clause to only return those records where MINE is > 0 but I keep messing it up.

can anyone help?

thanks!

RE: need help with query retuning only records where value > 0


We can't see what you see and our crystal ball is not working today.
Post the full SQL statement.
3eyes

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

RE: need help with query retuning only records where value > 0

Quote (Andreadd)

CODE

...SUM (A.INVOICE_AMOUNT) - B.INVOICE_AMOUNT) as MINE
...where MINE is > 0 

but I keep messing it up.

I'll bet that the errors you are receiving are either:

CODE

ORA-00904: "MINE": invalid identifier 

or (if you incorrectly have the word "is" in front of your ">" operator):

CODE

ORA-00908: missing NULL keyword 

...right?

If your error is the first one, above, then the problem is that "MINE" is an expression alias. Oracle recognizes expression aliases only as an "ORDER BY" reference (e.g., "...ORDER BY MINE") or when an outer SQL statement refers to the alias that a sub-query defines:

CODE

SELECT * FROM
    (SELECT <your other expressions>
           ,SUM (A.INVOICE_AMOUNT) - B.INVOICE_AMOUNT) as MINE
       FROM <table_name(s)>
    )
 WHERE MINE > 0; 

If your error is the second error, above, then remove the extraneous "IS", then see Error 1, above.

Let us know if this solves your problem.

santaMufasa
(aka Dave of Sandy, Utah, USA)
“People may forget what you say, but they will never forget how you made them feel."

RE: need help with query retuning only records where value > 0

(OP)
when i inserted SUM (A.INVOICE_AMOUNT) - B.INVOICE_AMOUNT) > '0' in the WHERE statement I got error -cannot perform GROUP. so I tried to do case when SUM (A.INVOICE_AMOUNT) - B.INVOICE_AMOUNT)> '0' then SUM (A.INVOICE_AMOUNT) - B.INVOICE_AMOUNT) as MINE
else null in the select statement I got needed right parens (remember i do mssql well, not this) then after adding too many parens i got missing FROM error

what I ended up doing in the end is inserting a HAVING clause after my group by statement:
having (SUM (A.INVOICE_AMOUNT) != B.INVOICE_AMOUNT)

my thinking is that if there is a difference greater than 0 then these 2 values would not be equal. it appears to work

RE: need help with query retuning only records where value > 0

add the following clause after any group by or where and before any order by

having SUM (A.INVOICE_AMOUNT) - B.INVOICE_AMOUNT) > 0

Bill
Lead Application Developer
New York State, USA

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close