ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 278k

How to get duplicate on PartId and Company Id both and have different

Jan 1 2021 12:31 AM

How to get duplicate on Part Id and Company Id both and have different Status ?

I work on SQL server 2012 I have issue I can't get duplicate on company id and part id

and on same time have different status

as partid 1211 and companyid 3030 repeated two times meaning two rows but with different status

pending and Done

so How to write query do that
  1. create table #PartsData  
  2. (  
  3. PartId int,  
  4. CompanyId int,  
  5. Status nvarchar(50)  
  6. )  
  7. insert into #PartsData(PartId,CompanyId,Status)  
  8. values  
  9. (1211,3030,'Pending'),  
  10. (1211,3030,'Done'),  
  11. (1599,4812,'NotFound'),  
  12. (1599,4812,'Pending'),  
  13. (9731,4050,'Inprogress'),  
  14. (9731,4050,'Done'),  
  15. (7801,4031,'Pending'),  
  16. (7822,9815,'Pending')  

  17. Expected result :  
  18.   
  19.  PartId    CompanyId    Status  
  20.  1211    3030    Pending  
  21.  1211    3030    Done  
  22.  1599    4812    NotFound  
  23.  1599    4812    Pending  
  24.  9731    4050    Inprogress  
  25.  9731    4050    Done

Answers (7)