ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 278.6k

How to select data based dynamically based on start and end of Affecte

Oct 5 2020 7:49 PM
I work on SQL server 2012 I need to get data from #partsdata table where part number matches
Affected Product both start and End
as Example where I have Affected Product as
APAMS-***G
then I will get Parts That have start APAMS- and End by G
start must be end with dash (-)
this roles applied to another rows on search data table .
I get part number that have matched with start f affected product and end with same charachter of affectedproduct
  1. create table #searchdata  
  2. (  
  3. Id int,  
  4. AffectedProduct nvarchar(50)  
  5. )  
  6. insert into #searchdata(Id,AffectedProduct)  
  7. values  
  8. (1,'APAMS-***G'),  
  9. (2,'APg-***F'),  
  10. (3,'Dom-***D')  
  11. create table #PartsData  
  12. (  
  13. PartId int,  
  14. PartNumber nvarchar(50)  
  15. )  
  16. insert into #PartsData(PartId,PartNumber)  
  17. values  
  18. (233,'APAMS-234G'),  
  19. (501,'APAMS-901G'),  
  20. (909,'APAMS-901G'),  
  21. (700,'APg-670F'),  
  22. (550,'APg-G3DF'),  
  23. (940,'APg-321F'),  
  24. (702,'Dom-670D'),  
  25. (710,'Dom-G3DD'),  
  26. (770,'APg-321L'),  
  27. (915,'APAMS-901M'),  
  28. (922,'APg-325N')  
Expected Result
  1. PartId    PartNumber  
  2.  233    APAMS-234G  
  3.  501    APAMS-901G  
  4.  909    APAMS-901G  
  5.  700    APg-670F  
  6.  550    APg-G3DF  
  7.  940    APg-321F  
  8.  702    Dom-670D  
  9.  710    Dom-G3DD  
 
so How to do that please ?

Answers (3)