Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL QUERY

Posted on 2011-09-23
7
Medium Priority
?
429 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
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 setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Via a live example, show how to take different types of Oracle backups using RMAN.

618 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