Hi @ahmed salah ,
Please refer the updated query from below and check whether it is working.
If not, please provide more sample data with different conditions and expected output.
select a.PartId,a.PartNumber from #PartsData a
inner join #searchdata b
on a.PartNumber like
---first part like APAMS- or APg- or Dom-
left(AffectedProduct,Charindex('-',AffectedProduct))+
---remaining part like ***G or ***F or ***D
replace(right(AffectedProduct,len(AffectedProduct)-(Charindex('-',AffectedProduct))),'*','_')
Or
select a.PartId,a.PartNumber from #PartsData a
inner join #searchdata b
on a.PartNumber like
---first part like APAMS- or APg- or Dom-
left(AffectedProduct,Charindex('-',AffectedProduct))
--second part after '-' like ***
+replace(substring(AffectedProduct,Charindex('-',AffectedProduct)+1,len(AffectedProduct)-(Charindex('-',AffectedProduct))-1),'*','_')
---last part like G or F or D
+RIGHT(AffectedProduct,1)
Best regards
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.