CREATE VIEW dbo.ApiItemsRepositoryView
as
select f.Parent ItemId, mag.ID RepositoryId
from dbo.Features  f
JOIN dbo.Magazyny mag ON  f.ParentType = 'Towary'  and f.Name LIKE '_widocznosc%' and f.DataKey='1'  and mag.Symbol = REPLACE(f.Name,'_widocznosc','') 
where  f.Name LIKE '_widocznosc%'