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 character of affected product
How to do that please ?
Expected Result
PartId PartNumber
233 APAMS-234G
501 APAMS-901G
909 APAMS-901G
700 APg-670F
550 APg-G3DF
940 APg-321F
702 Dom-670D
710 Dom-G3DD
create table #searchdata
(
Id int,
AffectedProduct nvarchar(50)
)
insert into #searchdata(Id,AffectedProduct)
values
(1,'APAMS-***G'),
(2,'APg-***F'),
(3,'Dom-***D')
create table #PartsData
(
PartId int,
PartNumber nvarchar(50)
)
insert into #PartsData(PartId,PartNumber)
values
(233,'APAMS-234G'),
(501,'APAMS-901G'),
(909,'APAMS-901G'),
(700,'APg-670F'),
(550,'APg-G3DF'),
(940,'APg-321F'),
(702,'Dom-670D'),
(710,'Dom-G3DD'),
(770,'APg-321L'),
(915,'APAMS-901M'),
(922,'APg-325N')