Просто предположение.Возможно, вам также нужны первичные блоки, которые не удовлетворяют самому фильтру, но некоторые из его альтернативных единиц удовлетворяют.
DECLARE @keyword nvarchar(10) = 'unit';
WITH alts AS (
SELECT [unit_id], [unit_name], [conversion],[alt_of], [alt_sort_no]
FROM T_DX_UNITS
WHERE alt_of IS NOT NULL AND unit_name LIKE '%' + @keyword + '%'
)
SELECT U.unit_id as primary_unit_id, U.unit_name as primary_unit,
alt_id1,
alt_unit1,
alt_conversion1,
alt_id2,
alt_unit2 ,
alt_conversion2,
alt_id3,
alt_unit3,
alt_conversion3
alt_id4,
alt_unit4,
alt_conversion4
FROM T_DX_UNITS U
CROSS APPLY (
SELECT
alt_id1 = (select top 1 unit_id from alts a where a.alt_of=U.unit_id and a.alt_sort_no=1),
alt_unit1 = (select top 1 unit_name from alts a where a.alt_of=U.unit_id and a.alt_sort_no=1),
alt_conversion1 =(select top 1 conversion from alts a where a.alt_of=U.unit_id and a.alt_sort_no=1),
alt_id2 = (select top 1 unit_id from alts a where a.alt_of=U.unit_id and a.alt_sort_no=2),
alt_unit2 = (select top 1 unit_name from alts a where a.alt_of=U.unit_id and a.alt_sort_no=2),
alt_conversion2 =(select top 1 conversion from alts a where a.alt_of=U.unit_id and a.alt_sort_no=2),
alt_id3 = (select top 1 unit_id from alts a where a.alt_of=U.unit_id and a.alt_sort_no=3),
alt_unit3 = (select top 1 unit_name from alts a where a.alt_of=U.unit_id and a.alt_sort_no=3),
alt_conversion3 =(select top 1 conversion from alts a where a.alt_of=U.unit_id and a.alt_sort_no=3),
alt_id4 = (select top 1 unit_id from alts a where a.alt_of=U.unit_id and a.alt_sort_no=4),
alt_unit4 = (select top 1 unit_name from alts a where a.alt_of=U.unit_id and a.alt_sort_no=4),
alt_conversion4 =(select top 1 conversion from alts a where a.alt_of=U.unit_id and a.alt_sort_no=4)
) t
WHERE U.alt_of IS NULL
AND (U.unit_name LIKE '%' + @keyword + '%'
OR coalesce(t.alt_id1, t.alt_id2, t.alt_id3, t.alt_id4) IS NOT NULL)