Solved

SQL QUERY

Posted on 2011-09-23
7
421 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now