Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Duplicate query

Author  Topic 

SQLWoman
Starting Member

1 Post

Posted - 2012-08-08 : 10:54:36
I am trying to find instances when IDCONTR_PART has two or more different IDCONTR_LEG associated with it. I have the query below but not sure if the syntax is right.


SELECT IDEMPR_PART, IDCENT_PART, CODPROD_PART, IDCONTR_PART, COUNT(CONTR_LEG)
FROM (
SELECT IDEMPR_PART, IDCENT_PART, CODPROD_PART, IDCONTR_PART, IDCONTR_LEG + IDSCONTR_LEG AS CONTR_LEG, COUNT(CONTR_LEG) AS COUNT
FROM SI_LACMIS
GROUP BY IDEMPR_PART, IDCENT_PART, CODPROD_PART, IDCONTR_PART, CONTR_LEG
HAVING COUNT(CONTR_LEG) > 1)
GROUP BY IDEMPR_PART, IDCENT_PART, CODPROD_PART, IDCONTR_PART
HAVING COUNT(CONTR_LEG) > 1;

I can try to explain it:
1. Define the Partenon Id = IDEMPR_PART + IDCENT_PART + CODPROD_PART + IDCONTR_PART
2. Define the Legacy Id = IDCONTR_LEG + IDSCONTR_LEG
3. Query for all the unique combinations of Partenon Id and Legacy Id
4. From the results of this query, determine if there are multiple records for any Partenon Id
5. If there are, they represent different Legacy Ids and we should research which ones are correct

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-08 : 11:02:26
your intial explanation and latter one is contradictory

IDCONTR_PART has two or more different IDCONTR_LEG associated with it


is not same as below

3.Query for all the unique combinations of Partenon Id and Legacy Id
4. From the results of this query, determine if there are multiple records for any Partenon Id


as latter speaks about considering combination and then look for duplicate instances

so please confirm what exactly you're looking at

former or latter?



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -