I have a problem with a Join that I can't seem to fix, this is the cut down version of code
SELECT top 5
a.Name00,
b.MIDNumber
FROM
[CM_UOC].[dbo].[Computer_System_DATA] AS a
LEFT OUTER JOIN
[UoC_Inventory].[dbo].[Inv_DATA] AS b on b.MIDNumber like '%'+a.Name00+'%'
Basically the ID's are the same but some ID's in a.Name00 have leading or trailing characters, such as "AVMID.." any matches based on these entries are found and joined but any columns selected from table 'b' are returned as NULL. The join is fine if there are no leading or trailing characters.
What I'm getting is
Name00 MIDNumber
AVMID014253 NULL
AVMID10059 NULL
AVMID10061 NULL
AVMID10063 NULL
AVMID10064 NULL
What I need is
Name00 MIDNumber
AVMID014253 MID14253
AVMID10059 MID10059
AVMID10061 MID10061
AVMID10063 MID10063
AVMID10064 MID10064
I understand that a LEFT JOIN will return null values if there isn't a match but how can I join and get the output I'm looking for?
EDIT
Fixed the leading characters with this
WITH A AS
(
SELECT 'M'+right(Name00, len(Name00) - charindex('M', Name00)) as 'A_MID'
FROM [CM_UOC].[dbo].[Computer_System_DATA]
),
B AS
(
SELECT MIDNumber AS 'B_MID'
FROM [UoC_Inventory].[dbo].[Inv_DATA]
)
SELECT * FROM A LEFT JOIN B ON (B.B_MID = A.A_MID)
WHERE B.B_MID IS NOT NULL
ORDER BY A_MID DESC
Still having problems trimming any leading characters