Solved

SQL QUERY

Posted on 2011-09-23
7
425 Views
Last Modified: 2013-12-07
Hi, I am having trouble with the following piece of SQL.

I have 2 Tables: POHEAD and POLINE - THEY SHOULD BE LINKED ON THE ORD_NO field, primary for both.  I am trying to identify and return lines on a purchase order where the same catalogue item has been ordered twice.

I want to get the ORD_NO from the POHEAD Table, ORD_NO & ORD_LIN_NO & CATALOGUE fron the POLINE table, where the same catalogue item has been ordered twice on 1 ORD_NO for sysdate.

I have tried a few options below the latest, but this is giving me an error back

SELECT
RSSPOHEAD.ORD_NO,
RSSPOLINE.ORD_NO      
FROM
RSSPOHEAD,
RSSPOLINE
WHERE
RSSPOHEAD.ORD_NO=RSSPOLINE.ORD_NO
AND
RSSPOLINE.STATUS <> 'Z'
 AND
RSSPOHEAD.ORD_DATE = to_char(sysdate,'YYYYMMDD')
HAVING
      count(RSSPOLINE.CATALOGUE) <>count (distinct RSSPOLINE.CATALOGUE)

0
Comment
Question by:sochionnaitj
  • 4
  • 2
7 Comments
 
LVL 9

Expert Comment

by:OCDan
ID: 36585623
Please can you post the eror that it comes up with?
0
 
LVL 2

Expert Comment

by:mehuje
ID: 36585635
please share the table structure with some sample value.....if i consider RSSPOLINE table have multiple entity for different CATALOGUE having same order id then you can try below sql..........not sure it will work or not...

SELECT  RSSPOHEAD.ORD_NO,RSSPOLINE.ORD_NO, count(RSSPOLINE.CATALOGUE)  cn    
FROM RSSPOHEAD, RSSPOLINE
WHERE RSSPOHEAD.ORD_NO=RSSPOLINE.ORD_NO
AND RSSPOLINE.STATUS <> 'Z'
AND RSSPOHEAD.ORD_DATE = to_char(sysdate,'YYYYMMDD')
GROUP BY RSSPOHEAD.ORD_NO,RSSPOLINE.ORD_NO, RSSPOLINE.CATALOGUE
HAVING  cn>1
0
 

Author Comment

by:sochionnaitj
ID: 36585752
OCDan: it comes back with: 100:SQL ERROR EXECUTING SQL: 3146
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sochionnaitj
ID: 36585760
mehuje: It is returning invaild identifier for cn

SQL> SELECT  RSSPOHEAD.ORD_NO,RSSPOLINE.ORD_NO, count(RSSPOLINE.CATALOGUE) cn
  2  FROM RSSPOHEAD, RSSPOLINE
  3  WHERE RSSPOHEAD.ORD_NO=RSSPOLINE.ORD_NO
  4  AND RSSPOLINE.STATUS <> 'Z'
  5  AND RSSPOHEAD.ORD_DATE = to_char(sysdate,'YYYYMMDD')
  6  GROUP BY RSSPOHEAD.ORD_NO,RSSPOLINE.ORD_NO, RSSPOLINE.CATALOGUE
  7  HAVING cn >1;
HAVING cn >1
       *
ERROR at line 7:
ORA-00904: "CN": invalid identifier
0
 
LVL 2

Accepted Solution

by:
mehuje earned 500 total points
ID: 36585768
then try this...

SELECT  RSSPOHEAD.ORD_NO,RSSPOLINE.ORD_NO, count(RSSPOLINE.CATALOGUE)
 FROM RSSPOHEAD, RSSPOLINE
 WHERE RSSPOHEAD.ORD_NO=RSSPOLINE.ORD_NO
 AND RSSPOLINE.STATUS <> 'Z'
 AND RSSPOHEAD.ORD_DATE = to_char(sysdate,'YYYYMMDD')
 GROUP BY RSSPOHEAD.ORD_NO,RSSPOLINE.ORD_NO, RSSPOLINE.CATALOGUE
  HAVING count(RSSPOLINE.CATALOGUE) >1
0
 

Author Comment

by:sochionnaitj
ID: 36586038
Thanks mehuje: - that has resolved it
0
 

Author Closing Comment

by:sochionnaitj
ID: 36586040
thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to recover a database from a user managed backup

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question