ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 254.7k

How to get parts related to every Code by Features related ?

Dec 29 2020 2:24 AM
I work on SQL server I face issue I can't display features related to every part by code
 
so part attribute table have parts with feature key 1502260016
 
and feature key 1502260016 related to code 8536698000
 
and code have 2 feature 1502260016 and 1502260001
 
so part must have two features or two rows not one row .
 
  1. create table #tradecodecontrol  
  2. (  
  3. Zplid int,  
  4. CodeTypeId int,  
  5. Code nvarchar(20),  
  6. FeatureKey int  
  7. )  
  8. insert into #tradecodecontrol(Zplid,CodeTypeId,Code,FeatureKey)  
  9. values  
  10. (25820,854838,'EAR99',NULL),  
  11. (25820,849774,'8538908180',1502260001),  
  12. (25820,849774,'8536698000',1502260001),  
  13. (25820,849774,'8536698000',1502260016),  
  14. (25820,849774,'8536694040',NULL)  
  15. CREATE table #partattributes  
  16. (  
  17. PartId int,  
  18. FeatureKey int  
  19. )  
  20. insert into #partattributes (PartId,FeatureKey)  
  21. values  
  22. (17890,1502260016),  
  23. (17830,1502260016),  
  24. (17705,1502260016),  
  25. (17910,1502260016),  
  26. (17880,1502260016)  
  27.   
  28. what I try is :  
  29.   
  30. select * from #partattributes ps  
  31. inner join #tradecodecontrol tc on ps.FeatureKey=tc.FeatureKey  
it display 5 rows for 5 parts as one Feature per Part
 
but exactly I need to get features related to every code so I need to display 2 Feature per every part
 
because feature key 1502260016 related to code 8536698000
 
and code 8536698000 have two features 1502260016 and 1502260001
 
so every part must have two features
 
this meaning total rows per 5 parts will be 10 rows as two feature per every part as below:
 
so how to get that please by sql query ?
 
Expected Result :
  1. PartId  FeatureKey  Zplid   CodeTypeId  Code    FeatureKey  
  2. 17890   1502260016  25820   849774  8536698000  1502260016  
  3. 17890   1502260016  25820   849774  8536698000  1502260001  
  4. 17830   1502260016  25820   849774  8536698000  1502260016  
  5. 17830   1502260016  25820   849774  8536698000  1502260001  
  6. 17705   1502260016  25820   849774  8536698000  1502260016  
  7. 17705   1502260016  25820   849774  8536698000  1502260001  
  8. 17910   1502260016  25820   849774  8536698000  1502260016  
  9. 17910   1502260016  25820   849774  8536698000  1502260001  
  10. 17880   1502260016  25820   849774  8536698000  1502260016  
  11. 17880   1502260016  25820   849774  8536698000  1502260001  

Answers (1)