?
Solved

SQL QUERY

Posted on 2011-09-23
7
Medium Priority
?
427 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Suggested Courses

771 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